【发布时间】:2013-06-29 10:39:59
【问题描述】:
我正在尝试在 UITableView 中选择的行中设置复选标记(放置在弹出视图中)。其实我有这样的东西:
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Check if current row is selected
Boolean isNowChecked = NO;
if([self.tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark)
{
isNowChecked = YES;
}
if(isNowChecked)
{
[self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
else
{
[self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
return indexPath;
}
结果我可以选择行,例如我触摸第一个项目然后我看到复选标记。当我向下滚动表格视图时,我看到我还检查了其他项目(编号 17、32)。当我取消选中我的第一个项目时,每个检查也会消失。
您对造成这种情况的原因有什么建议,我该如何避免?
【问题讨论】:
-
你的
tableView:cellForRowAtIndexPath:看起来如何(即你如何实例化你的单元格)? -
我认为您没有使用 UITableViewCell 的适当可重用性。所以添加你的 cellForRowAtIndexPath 方法的代码
-
是的,你是对的。我在 cellForRowAtIndexPath 中有错误的实现。
标签: ios objective-c uitableview ios6 xcode4