【问题标题】:How to hide custom check mark in table view如何在表格视图中隐藏自定义复选标记
【发布时间】:2012-03-12 17:41:32
【问题描述】:

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

提前致谢。 -PaulS。

- (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;
//    }

}

【问题讨论】:

标签: ios5 uitableview xcode4.2


【解决方案1】:
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.

【讨论】:

  • 由于所有数据都是我的核心数据实体的一部分,因此在实体中将其作为新的 BOOL 属性进行跟踪是否有意义,然后解析值,在选择行时修改对象?
【解决方案2】:

您可以通过此代码获取 tableview 的每个单元格 UITableViewCell *cell=[product_table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:clickedTag inSection:0]]; 做一个for循环。

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

对于除当前行之外的每个单元格,当前行只显示一个图像。

【讨论】:

    猜你喜欢
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    相关资源
    最近更新 更多