#pragma mark - tableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//self.indexPathSelect記錄上一次選中的位置
//把上一個選擇的cell取消
if (self.indexPathSelect) {
UITableViewCell *selectCell = [tableView cellForRowAtIndexPath: self.indexPathSelect];
selectCell.accessoryType = UITableViewCellAccessoryNone;
}
//更新記錄,選中點擊的cell
self.indexPathSelect = indexPath;
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier forIndexPath:indexPath];
//根據(jù)記錄的位置防止重用產(chǎn)生問題
cell.accessoryType = (self.indexPathSelect == indexPath) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return cell;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者