奇怪的分组tableview配件问题

时间:2011-03-18 21:35:12

标签: iphone objective-c uitableview uialertview

我目前有一个显示分组表格视图的UIAlertview,并且花了整整一周才使它正常工作,我离开本来应该是最简单的部分,直到最后,添加配件。我想要的只是在点击时将行显示为已选中。这听起来很简单乍一看工作得很好。如果我在0,0点击单元格,它会被勾选但是如果我然后向下滚动我也最终得到2,1被勾选而3,6(并且0,0再次被取消)。我查看了This Question并在另一个分组表上测试了他们的代码,它运行正常,但对我的警报表没有任何影响。

这是我正在使用的代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    cell.accessoryType = UITableViewCellAccessoryCheckmark;

}

我认为这不能修改多个单元格。我在那里设置了一个断点,每次点击只召唤一次。

Cellforrowatindex方法:

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {

      static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

      NSArray *listData =[self.data objectForKey:

      [self.sortedKeys objectAtIndex:[indexPath section]]];

      UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];

     if(cell == nil) {

         cell = [[[UITableViewCell alloc]
             initWithStyle:UITableViewCellStyleDefault
             reuseIdentifier:SimpleTableIdentifier] autorelease];
      }

    NSUInteger Row = [indexPath row];
    cell.textLabel.text = [listData objectAtIndex:Row];

    return cell;
}

感谢。

1 个答案:

答案 0 :(得分:1)

我在想,因为您正在重复使用UITableViewCells,一旦更改了一个单元的accessoryType,它可能会影响表视图中的其余单元格。

获得cellForRowAtIndexPath对象后,在cell内,执行以下操作:

cell.accessoryType = UITableViewCellAccessoryNone

希望它有所帮助。