UITableView加載Cell的幾種方式(請(qǐng)自行替換掉類名)

1:基本

static NSString *cellIdentifier1 = @"strIDone";

NewsSingleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier1];

if (!cell) {

cell = [[ NewsSingleTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier1];

}


2:復(fù)用自定義xib的cell


一:↓↓↓↓↓↓↓↓↓↓↓↓↓

在cell內(nèi)

(其中.h)

+(instancetype)GetCellWithTableView:(UITableView *)tableView;

(其中.m)

+(instancetype)GetCellWithTableView:(UITableView *)tableView

{

static NSString *swithCell=@"CZdataViewCell";

CZdataViewCell *cell=[tableView dequeueReusableCellWithIdentifier:swithCell];

if (!cell) {

cell=[[[NSBundle mainBundle]loadNibNamed:@"CZdataViewCell" owner:nil options:nil] firstObject];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

return cell;

}

(在tableView中)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

CZdataViewCell *bjcell = [CZdataViewCell GetCellWithTableView:tableView];

return bjcell;

}


二:↓↓↓↓↓↓↓↓↓↓↓↓↓

在tableview中:

- (void)viewDidLoad {

[super viewDidLoad];

// 注冊(cè)重用加載類

UINib *nib = [UINib nibWithNibName:@"DetailDataCell" bundle:nil];

[_detailTableView registerNib:nib forCellReuseIdentifier:@"cell"];

}

// cell內(nèi)容部分

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

DetailDataCell? *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

return cell;

}

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

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

  • 概述在iOS開(kāi)發(fā)中UITableView可以說(shuō)是使用最廣泛的控件,我們平時(shí)使用的軟件中到處都可以看到它的影子,類似...
    liudhkk閱讀 9,289評(píng)論 3 38
  • #pragma mark someValueAboutTableView 1.tableView的樣式:UITab...
    瀟巖閱讀 1,049評(píng)論 0 0
  • UITableView內(nèi)置了兩種樣式:UITableViewStylePlain,UITableViewStyle...
    Windv587閱讀 429評(píng)論 0 1
  • 關(guān)于成交量,股市中流傳著這么一句話:技術(shù)指標(biāo)千變?nèi)f化,唯有成交量是最實(shí)在的買賣。成交量的大與小,是推動(dòng)股價(jià)變化的最...
    艾尚說(shuō)股市閱讀 276評(píng)論 0 0
  • 暑假的日常熬夜,想起那些個(gè)曾經(jīng)兩點(diǎn)睡六點(diǎn)起連續(xù)一周,卻依然元?dú)獬渑娴伛雎?tīng)每一節(jié)課程、迎接每一項(xiàng)挑戰(zhàn)的日子。 彼時(shí)朝...
    李帥帥angkuLC閱讀 225評(píng)論 0 0

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