動態切換tableView中的cell的種類

2021-09-06 17:51:47 字數 2233 閱讀 3570

動態切換tableview中的cell的種類

為什麼要動態切換tableview中cell的種類呢?如果專案經理不出這種需求,你也就見不到這篇文章了:)

效果:

原始碼:首先,你要準備3種cell,直接繼承系統的就行了.

切換標籤

@property (nonatomic, strong) nsarray *dataarray; //

資料來源@property (nonatomic, strong) nsarray *reddata; //

紅色cell資料

@property (nonatomic, strong) nsarray *yellowdata; //

黃色cell資料

@end

@implementation

rootviewcontroller

- (void

)viewdidload

- (void)runselector:(id

)sender

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath

if (indexpath.row != 0) //

其他cell

if([_changeflag isequaltostring:cell[yellow]])

}return

cell;

}- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath

if([_changeflag isequaltostring:cell[red]])

if([_changeflag isequaltostring:cell[yellow]])

return0;

}@end

分析:用這個來標示重用吧

有乙個標籤是用來切換cell型別的,以及對應的資料來源

根據切換標籤來決定初始化哪一種cell

就是這樣子實現的.

qml 動態建立TableView

在qml應用開發中,經常會用到tableview來顯示資料,而有時 又不是固定的,需要根據不同的情況來變換 的標題和內容。本次部落格將會介紹怎樣在qml中動態的建立tableview。首先建立乙個檔案datashowtable.qml,首字母要大寫,這些大家應該都知道吧。import qtquick...

iOS監聽tableView組頭切換事件

void tableview uitableview tableview willdisplayheaderview uiview view forsection nsinteger section 組頭將要出現的時候系統會呼叫 void tableview uitableview tablevie...

動態改變tableview的cell的高度

乙個最簡單的方法 在tableview uitableview tableview heightforrowatindexpath nsindexpath indexpath方法中根據cell裡面內容的高度來改變,如下 cgfloat tableview uitableview tableview ...