【问题标题】:Calling super for cellForRowAtIndexPath in Swift在 Swift 中为 cellForRowAtIndexPath 调用 super
【发布时间】:2014-06-30 00:13:31
【问题描述】:

如果有人可以帮助我使用调用 super 以从 func tableView (tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) 中获取 UITableViewCell 的语法,我将不胜感激。这是一个静态表。

override func tableView (tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
//  The Objective-C code is: UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
var cell = super.??
}

我已经尝试过,但似乎无法获得正确的语法来执行此操作。提前致谢。

【问题讨论】:

    标签: uitableview swift


    【解决方案1】:
    var cell = super.tableView(tableView, cellForRowAt: indexPath)
    

    【讨论】:

    • 非常感谢!我以为我试过了(大约百万次)!!
    • 请问调用 super 有什么作用?我在 Apple 的 HomeKit 应用程序中看到此代码,但我不理解此代码。通常我们将它出列并以我们想要的方式修改单元格,但是调用 super?
    • @huggie 这仅适用于界面生成器中定义的静态表视图。调用 super 将为您提供已在 xib 文件中设置的静态单元格。
    【解决方案2】:

    Swift 3 更新:

    var cell = super.tableView(tableView, cellForRowAt: indexPath)
    

    【讨论】:

      【解决方案3】:

      对我有用的是。

      let cell = someController.tableView.cellForRow(at: NSIndexPath(row: item, section: 0) as IndexPath) 
      

      【讨论】:

        【解决方案4】:

        在 Swift 4 和 ios 10+ 中

        1. 创建网点。
        2. oneCellOutlets.IsHidden = true

          override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
          
          let cell = super.tableView(tableView, cellForRowAt: indexPath)
          
          if cell.isHidden == true
          {
              return 0
          }
          else{
              return super.tableView(tableView, heightForRowAt: indexPath)
          }
          }
          

        【讨论】:

          猜你喜欢
          • 2016-06-24
          • 1970-01-01
          • 1970-01-01
          • 2011-12-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多