【问题标题】:Candidate has non-matching type UITableView?候选人有非匹配类型的 UITableView?
【发布时间】:2014-09-12 06:01:01
【问题描述】:

Xcode 说“候选人的 UITableView 类型不匹配.....”有人知道如何解决这个问题吗?

func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) 
-> Int {
        return dataSource[section].count
       }

func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath!) 
-> UITableViewCell? {
        let cell = tableView!.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)                   as             UITableViewCell

        if let path = indexPath{
            let currentString = dataSource[path.section][path.row]
            cell.textLabel?.text = currentString
        }
        return cell
    }

【问题讨论】:

  • 欢迎来到 Stackoverflow。对场景的更多解释可能有助于专家理解问题。

标签: ios cocoa-touch uitableview swift


【解决方案1】:

函数签名已更改。您需要更新到这些:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int)  -> Int {

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

【讨论】:

  • 谢谢!第一个现在可以工作,但是在我删除“!”后“if let path = indexPath”上出现错误,并说“条件绑定中的绑定值必须是可选类型”。我该怎么办?
  • 由于 indexPath 不再是可选的,您不需要 if 条件。尝试删除它。
  • 现在运行良好。非常感谢。
猜你喜欢
  • 2020-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-15
相关资源
最近更新 更多