使用場(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)用
