【发布时间】:2011-04-28 14:45:20
【问题描述】:
在我的应用程序中,如果用户按下 UITableView 中的任何单元格,则单元格的附件类型将设置为复选标记,如下所示
-(void)Check:(UITableView *)tableView Mark:(NSIndexPath *)indexPath
{
[self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
buttonCount++;
[selectedCellArray addObject:indexPath];
}
如果用户按下相同的单元格,则取消选中将发生如下情况
-(void)UnCheck:(UITableView *)tableView Mark:(NSIndexPath *)indexPath
{
[self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
buttonCount--;
if (buttonCount == 0) {
[selectedCellArray removeAllObjects];
}
}
我叫这个
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark)
{
[self UnCheck:tableView Mark:indexPath];
}
else
{
[self Check:tableView Mark:indexPath];
}
问题是当我按下第一个单元格时,它会调用 Check 方法并将单元格标记为,但是当我向下滚动时,我发现还有 2-3 个 cheked 单元格...即使我没有选择那些单元格...我没有知道为什么以及如何自动检查...
我希望有人知道问题出在哪里
非常感谢
【问题讨论】:
标签: iphone objective-c arrays uitableview