【问题标题】:iPhone deselect row after delayiPhone在延迟后取消选择行
【发布时间】:2011-06-29 09:00:32
【问题描述】:

我想知道是否有人知道在延迟后取消选择表格视图的方法?

我正在使用deselectRowAtIndexPath 方法。我只想在取消选择之前突出显示一秒钟。

谢谢!

【问题讨论】:

    标签: ios objective-c swift uitableview uitableviewrowaction


    【解决方案1】:

    我可以使用 [tableView deselectRowAtIndexPath:indexPath animated:YES]; 做到这一点

    另一种方法是:

    [self performSelector:@selector(deselect:) withObject:self afterDelay:0.33];
    

    然后创建一个调用deselectRowAtIndexPath的方法deselect

    【讨论】:

    • +1 这是我将使用的,尽管根据您所拥有的,deselect 方法应该采用一个参数(您将 self 作为参数传递),这意味着它至少会被称为deselect:
    • 正是我想要的。谢谢!
    【解决方案2】:

    如果您想要完成的是:点击一行,查看突出显示,突出显示消失,您可以:

    didSelectRowAtIndexPath

    //after you do whatever your doing when a row is selected
    UITableViewCell *cell [tableView cellForRowAtIndexPath:indexPath];
    [cell setSelected:NO];
    

    如果我没有误解你的话,这将产生你想要的效果。

    【讨论】:

      【解决方案3】:
      [self performSelector:@selector(deselect:) withObject:self afterDelay:0.33];
      

      Swift 版本:

      要在取消选择表格视图单元格时添加轻微延迟,您需要在tableView(_:didSelectRowAt:) 中添加以下内容:

      DispatchQueue.main.asyncAfter(deadline: .now() + 0.33) {
         self.deselectRow(at: indexPath, animated: true)
      }
      

      【讨论】:

        猜你喜欢
        • 2019-10-26
        • 2013-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-03
        • 1970-01-01
        相关资源
        最近更新 更多