IOS开发之tableview只选中一行
来源:未知 责任编辑:责任编辑 发表时间:2014-01-25 11:34 点击:次
场景:一个弹出层,包含一个Tableview,每一行为一个选择条件,且只能选择一个。选中后文体有颜色变化,后面还会有对勾。选择另一个后,前一个恢复成普通状态。
示例代码:
- (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];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}注意: lastIndexPath为私有变量,页面第一次加载为nil,需追加判断。
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>









![[iPhone中级]iPhone团购信息客户端的开发 (二)](/uploads/allimg/131022/200H11235-0-lp.png)
