【问题标题】:UITableView lose selected state iOSUITableView 失去选中状态 iOS
【发布时间】:2011-11-21 02:03:59
【问题描述】:

我有一个 UITableView 并拥有它,所以当您按下第一个单元格时,它会将您带到一个新视图(新 xib)。当您按下第二个单元格时,您会转到另一个视图,依此类推。当您转到任何这些新视图并返回 tableview 视图时,您刚刚按下的单元格仍处于选中状态(突出显示为蓝色)。解决这个问题的代码是什么?

【问题讨论】:

    标签: iphone ios uitableview state highlight


    【解决方案1】:

    在您的 tableView 数据源委托方法中:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    

    【讨论】:

      【解决方案2】:

      这很容易..

      在您推送新视图的相同方法中,您应该添加以下行:

      [tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated];
      

      【讨论】:

        【解决方案3】:

        在 tableView 的 viewWillAppear 中,您希望从中删除选择的单元格:

        UITableViewCell *cell = (UITableViewCell *)[myTableView cellForRowAtIndexPath:lastSelected];
        [cell setSelected:NO];
        

        其中 lastSelected 可以是 NSIndexPath 类型的全局变量,存储来自上述 UITableView 的 didSelectRowAtIndexPath 的 indexPath

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-06-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-03-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多