导航控制器与表格视图开发实践
1. 表格行选择与复选标记处理
在表格视图中,我们需要对当前选中的行进行特殊处理,为其设置复选标记。以下是实现该功能的关键代码:
cell.accessoryType = (row == oldRow && lastIndexPath != nil) ?
UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
当用户选择新的行时,我们需要更新选中状态,代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int newRow = [indexPath row];
int oldRow = [lastIndexPath row];
if (newRow != oldRow) {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



