2011-03-15 94 views
1

在我的应用我有UITableView &我用表格单元格indicater问题

[cell setAccessoryType:UITableViewCellAccessoryCheckmark]; 

,当我滚动此表,然后我得到多个勾选多种细胞

请帮助我..

+1

你可以发布你的代码吗?你在哪里设置单元配件视图以便更好地理解你的代码。 – Jhaliya 2011-03-15 08:41:58

回答

1

一般来说,细胞来自2种方式:

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

    static NSString *identifier = @"Cell"; 
    UITableViewCell *cell = ... // The cell come from reuse queue. 
    if (cell == nil) { 
     cell = ... // if reuse queue has no cell, then create an autoreleased cell 
    } 

    // Configure cell by indexPath. 
    // You should configure cell HERE. 

} 

Bec ause你的单元可能来自重用队列,它被配置。显然,你忘记重新配置来自重用队列的单元。

1

可以在的tableView的委托方法didSelectedRowAtIndexPath使用此示例代码

的UITableViewCell *细胞= [的tableView的cellForRowAtIndexPath:indexPath]; [cell setSelected:YES animated:YES]; [cell setAccessoryType:UITableViewCellAccessoryCheckmark];

for(int iterator=0;iterator<3;iterator++) 
    { 

     UITableViewCell *eachCell = [[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:iterator inSection:0]]; 
     [eachCell setSelected:NO animated:YES]; 
     [eachCell setAccessoryType:UITableViewCellAccessoryNone]; 
    } 

    UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath]; 
    [newCell setSelected:YES animated:YES]; 
    [newCell setAccessoryType:UITableViewCellAccessoryCheckmark];