类方法中使用实例方法

2022-11-17  本文已影响0人  寒雨晚风

1. 写当前类的全局类方法 普通的View

+ (DetailInfoView*)sharedView {

    static DetailInfoView* planView;

    if(!planView) {

        planView = [[DetailInfoView alloc]init];

        UIView *view = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([DetailInfoView class]) owner:planView options:nil].firstObject;

        [planView addSubview:view];

    }

    return planView;

}

1. 写当前类的全局类方法  tableView

+ (ListACell*)sharedViewFromTableView:(UITableView*)tableView {

    static ListACell* roomCell;

    if(!roomCell) {

        roomCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ListACell class])];

    }

    return roomCell;

}

2. 在类方法中 使用

+ (CGFloat)heightForModel:(id)model forTableView:(tableView*)tableView {

 DetailInfoView *viewHolder = [self  sharedView];

viewHolder 各个属性就能使用啦!

}

上一篇下一篇

猜你喜欢

热点阅读