2011-06-02 54 views
2

我在的UITableView工作,并试图让用户使用此代码UITableViewCell和UITableView重复选择其他单元格?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSInteger row = [indexPath row]; 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    if(cell != nil) 
    { 
     if(cell.accessoryType == UITableViewCellAccessoryNone) 
     { 
      cell.accessoryType = UITableViewCellAccessoryCheckmark; 
     } 
     else 
     { 
      cell.accessoryType = UITableViewCellAccessoryNone; 
     } 
    } 
} 

选择单元格,但问题是,当在一个页面中的细胞计数,如果你选择单元编号1的行号1每个页面也会被选中。

回答

8
static NSString * cellIdentifier = @"CellIdentifier" 

在这个地方使用

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i",indexPath.row]; 
+0

为什么第二个答案?你应该编辑你的第一个答案。 – EmptyStack 2011-06-03 08:29:47

+0

谢谢!你能解释为什么这解决了这个问题吗? – 2012-08-20 13:34:59

+0

你救了我的一天。谢谢。这解决了问题! – birdcage 2016-01-06 07:29:51

5

尼斯的答案,你真的帮把我在正确的轨道上。

我的2美分,收于帮助别人:

我使用分组的表,所以我改变它一点,使它:

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i-%i", indexPath.section, indexPath.row]; 

希望这有助于别人。

2

使用这个将全局变量的一个类传递给其他类或一个视图控制器到另一个视图控制器。

globalString=[Arrayname objectAtIndex:indexPath.row]; 

将此代码写入tableviewdidselect委托方法。

相关问题