【问题标题】:Fix for getting "deprecated and will be removed in Swift 4" warning for tableView functions修复了 tableView 函数的“已弃用并将在 Swift 4 中删除”警告
【发布时间】:2017-11-27 06:19:15
【问题描述】:

我刚刚将我的代码升级到 Swift 4,现在在控制台上收到所有 tableView 函数的警告。

tableView:willDisplayCell:forRowAtIndexPath:] is deprecated and will be removed in Swift 4; add explicit '@objc' to the declaration to emit the Objective-C entrypoint in Swift 4 and suppress this message

tableView:cellForRowAtIndexPath:] is deprecated and will be removed in Swift 4

【问题讨论】:

    标签: ios uitableview tableview deprecated swift4


    【解决方案1】:

    使用下面的代码cellForRow

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    }
    

    使用下面的一个来识别正在显示的单元格

    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    }
    

    如果您对数据源和委托函数有疑问,请选择 UITableViewDataSource 或 UITableViewDelegate 并右键单击跳转到定义,这将导致获取您的函数

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      我不建议任何人像这样解决这个问题,但它确实对我有用。 您可以在您使用的每个 tableView 函数的开头添加“@objc”。

      像这样:

      @objc func tableView(_ tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
          return 1
      }
      

      【讨论】:

        猜你喜欢
        • 2017-05-25
        • 2015-12-25
        • 2017-08-02
        • 1970-01-01
        • 2016-12-07
        • 1970-01-01
        • 2021-08-04
        • 1970-01-01
        相关资源
        最近更新 更多