2012-03-12 76 views
0

我有一个UITableiew,我希望能够显示一个自定义复选标记,当该行被选中(点击),但是,如果有任何其他的复选标记行,它必须被隐藏。做这个的最好方式是什么? IF ...似乎根本不起作用,它不会像我想的那样隐藏和取消隐藏复选标记。如何隐藏表视图中的自定义复选标记

在此先感谢。 - 保罗。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    home_2_CustomCell *cell = (home_2_CustomCell*)[tableView cellForRowAtIndexPath:indexPath]; 

    //This will hide the selected row... 
    cell.imageViewDidSelectRow.hidden = YES; 

// if (cell.imageViewDidSelectRow.hidden = NO){ 
//  cell.imageViewDidSelectRow.hidden = YES; 
// } 

} 
+0

在这里找到答案:http://stackoverflow.com/questions/5959950/iphone-uitableview-cellaccessory-checkmark – 2012-03-13 01:57:09

回答

0
1) Maintain a tag in class level as an NSIndexPath variable. 
2) Whenever a cell is selected make note of the indexPath and reload the table view. 
3) In cellForRowAtIndexPath delegate check for this variable and set marks accordingly. 
4) This will not be costly if you have the cell with less information. 
+0

由于所有的数据都是我的核心数据实体的一部分,是否有意义在实体中跟踪它为一个新的BOOL属性,然后解析这些值,在选择行时修改对象? – 2012-03-12 19:27:11

0

可以通过此代码 的UITableViewCell得到的tableview的每个小区*细胞= [product_table的cellForRowAtIndexPath:[NSIndexPath indexPathForRow:clickedTag切入口:0]]; 做一个循环。

for(int i=0;i<[tabledata count];i++){ 
cell.imageViewDidSelectRow.hidden = YES; 
} 

对于每个单元格,除了当前行被选中,并且您只有一个图像显示为当前行。

相关问题