【发布时间】:2014-06-03 15:10:52
【问题描述】:
这是我的代码,它显示了 14 行表格视图的问题。对于一个屏幕,可以看到 6 个单元格。
当我点按第 2 个单元格时,第 10 个单元格也有一个复选标记,点按第 3 个然后第 11 个复选标记,第 1 个然后第 9 个复选标记,点按第 1 个然后第 8 个复选标记...但是灰色突出显示的行为不是这样,只有可以突出显示一个单元格。
如果我在同一屏幕上点击一个单元格后点击一个单元格,则刚刚勾选的单元格将被清除为勾选标记,这是有道理的。但是,如果在我点击一个单元格然后向下滚动表格视图之后,我可以点击一个单元格并且它也显示复选标记,即刚刚在顶部屏幕上选中的那个仍然有复选标记。因此,如果我上下滚动,每次滚动到另一侧后点击一个单元格,我可以为每个单元格打上复选标记,所有复选标记都会显示出来。
真的很奇怪,我已经尝试了很多方法来解决它,但似乎我对UITableView失踪有一些基本的了解,请问有没有人可以解决?谢谢。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID= @"UITableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
cell.imageView.image = [UIImage imageNamed:@"earth.png"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
}
【问题讨论】:
标签: ios objective-c uitableview