UITableViewCell實(shí)現(xiàn)多選、全選、全不選

使用場(chǎng)景之一:購物車的時(shí)候用到

1、設(shè)置cell可多選屬性

_tableV.allowsMultipleSelection = YES;

2、設(shè)置cell選擇狀態(tài)

cell.selectionStyle =UITableViewCellSelectionStyleNone

3、在cell上自定義一個(gè)選擇Button(自定義名為:checkBtn),Button的selected屬性跟cell里的selected的屬性綁定。設(shè)置Button的兩種狀態(tài):UIControlStateNormal和UIControlStateSelected的不同狀態(tài)圖片。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

? ? ? ? [super setSelected:selected animated:animated];

? ? ? ? ?self.checkBtn.selected = selected;

}

4、獲取所有被選中的cell的NSIndexPath數(shù)組

NSArray * selectRows = self.tableV.indexPathsForSelectedRows;

5、全選可使用這個(gè)系統(tǒng)方法實(shí)現(xiàn)

- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;

6、取消全選可以用這個(gè)系統(tǒng)方法實(shí)現(xiàn)

- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;


7、附圖:全選/取消全選調(diào)用

最后編輯于
?著作權(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)容

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