1 聲明一個(gè)標(biāo)示 selectindex 包含selection和row
@property (nonatomic, assign) NSIndexPath *selectIndex;
2 設(shè)置默認(rèn)選中第一個(gè)
self.selectIndex = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableview selectRowAtIndexPath:self.selectIndex animated:YES scrollPosition:UITableViewScrollPositionNone];
3 cell for row 判斷 選中那個(gè) selectindex 和indexpath 是否相等判斷是否選中
NSInteger row = [indexPath row];
NSInteger oldrow = [self.selectIndex row];
if (row == oldrow && self.selectIndex != nil){
[cell.selectImageView setImage:UIImageMake(@"czzhong")];
}else{
[cell.selectImageView setImage:UIImageMake(@"czweixuanzhong")];
}
4 didselect 中判斷 根據(jù)樣式 更改以前選中的cell 樣式 重新給selectindex 賦值 設(shè)置選中的cell 樣式
HomePaytypeViewCell *cell = [tableView cellForRowAtIndexPath:_selectIndex];
[cell.selectImageView setImage:UIImageMake(@"czweixuanzhong")];
_selectIndex = indexPath;
HomePaytypeViewCell *cell1 = [tableView cellForRowAtIndexPath:indexPath];
[cell1.selectImageView setImage:UIImageMake(@"czzhong")];
[tableView reloadData];