自定義tableView的section heade/footerView時的view復用問題

自定義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;
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容