美文网首页
自定义tableView的section heade/foote

自定义tableView的section heade/foote

作者: 冉俊 | 来源:发表于2017-11-06 13:56 被阅读74次

自定义tableView的section heade/footerView时的view复用问题

1.首先要自定义一个sectionHeadView/sectionFootView继承自UITableViewHeaderFooterView,如下:
@interface FriendCircleView : UITableViewHeaderFooterView

2.在自定义的sectionHeadView/sectionFootView中重写这个方法,设置复用

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {   
        [self creatUI];
    }
    return self;
}

3.在需要调用自定义sectionHeadView/sectionFootView的VC里面调用table的代理方法,用法跟cell的复用相似

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    static NSString *viewIdentfier = @"headView";
    FriendCircleView *sectionHeadView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:viewIdentfier];
    if(!sectionHeadView){
        sectionHeadView = [[FriendCircleView alloc] initWithReuseIdentifier:viewIdentfier];
    }
    sectionHeadView.friendCircleModel = datas[section];
    return sectionHeadView;
}

相关文章

网友评论

      本文标题:自定义tableView的section heade/foote

      本文链接:https://www.haomeiwen.com/subject/rlllmxtx.html