幾種UITableview自定義Cell的辦法

https://blog.csdn.net/feng2qing/article/details/51407156

1>純代碼自定義UITableviewCell

繼承UITableviewCell,重寫cell的initWithStyle:withReuseableCellIdentifier

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

? ? if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

? ? ? ? //布局cell內(nèi)部控件? ? ? ? [self setupUI];

? ? }

? ? return self;

}

為tableView注冊cell,使用registerClass:forCellReuseIdentifier:方法注冊

[_tableView registerClass:[FooterCell Class] forCellReuseIdentifier:CellIdentifier];


在cellForRowAtIndexPath中使用dequeueReuseableCellWithIdentifier:forIndexPath:獲取重用的cell,若無重用的cell,將自動使用所提供的class類創(chuàng)建cell并返回

FooterCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];?

獲取cell時若無可重用cell,將調(diào)用cell中的initWithStyle:withReuseableCellIdentifier:方法創(chuàng)建新的cell

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容