【问题标题】:Modify cell on didSelectRowAtIndexPath in UITableView在 UITableView 中修改 didSelectRowAtIndexPath 上的单元格
【发布时间】:2014-07-20 09:55:09
【问题描述】:

我在表格视图单元格 view1 和 view2 上有 2 个视图,我想要做的是当我点击一个单元格时,我希望隐藏 view1 并显示 view2(在开始时显示 view1 而 view2 是隐藏),我为视图 view1 = 102 和 view2 = 103 使用了标签,由于某种我无法理解的原因,view1 被隐藏但 view2 不显示。

这是我的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];


    UIView * view1 = (UIView *)[cell viewWithTag:102];
    UIView * view2 = (UIView *)[cell viewWithTag:103];

    [view1 setHidden:YES];
    [view2 setHidden:NO];


    NSLog(@"View 2 is : %hhd",view2.hidden);


}

故事板

模拟器

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    而不是

    cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    

    使用

    cell = [tableView cellForRowAtIndexPath:indexPath];
    

    因为dequeueReusableCellWithIdentifier: forIndexPath: 将返回当前不可见的当前未使用的表格单元格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-23
      • 1970-01-01
      • 2012-01-14
      相关资源
      最近更新 更多