【问题标题】:cannot invoke 'dequeReusable...' with an argument of type '(String)'无法使用“(字符串)”类型的参数调用“dequeReusable...”
【发布时间】:2015-05-27 05:26:37
【问题描述】:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:   NSIndexPath) -> UITableViewCell {

    var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

    cell.textLabel!.text = self.funlists[indexPath.row]

    return cell
}

无法使用“(字符串)”类型的参数调用“dequeReusable...” 在线 var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

(对不起,我对 Xcode 和 swift 非常陌生) 当我在我的故事板中单击我的 UITableView 时,它是一个表格视图单元格,带有样式子标题和标识符单元格。 (我可能完全错了,不确定)

【问题讨论】:

  • var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell",forIndexPath: indexPath) as UITableViewCell
  • 在故事板中定义单元格标识符
  • @Memon,谢谢我在情节提要中定义了单元格标识符。当我将代码行更改为您提供的内容时,我收到错误消息:无法在行上使用类型为“(String,forIndexPath:NSindexPath)”的参数调用“dequeReusable ...”

标签: ios uitableview swift parse-platform


【解决方案1】:

我想我找到了问题所在,尝试在dequeueReusableCellWithIdentifier 调用中取词self,如下所示:

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

    var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

    cell.textLabel!.text = self.funlists[indexPath.row]

    return cell
}

原因是你想使用来自函数的tableView,而不是属于类的tableView。

如果这能解决您的问题,请告诉我

【讨论】:

  • @moez05 那是因为返回一个 AnyObject 并且 swift 不确定它是否可以转换为 UITableViewCell,把!你强制转换的代价是如果你错了应用程序会崩溃,但是在这种情况下你可以确定使用这个函数总是返回一个 UITableViewCell,我不知道为什么苹果在这里放一个 AnyObejct 作为返回类型。跨度>
【解决方案2】:

请在情节提要中定义您的单元格标识符。

【讨论】:

  • 好像我已经这样做了,但错误仍然存​​在
  • 在 swift 中查看这篇文章以获得表格视图 - weheartswift.com/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多