gpt4 book ai didi

ios - 切换到 xcode 6 GM - 突然 Controller 不再符合 UITableViewDataSource

转载 作者:行者123 更新时间:2023-12-01 17:22:35 25 4
gpt4 key购买 nike

今天我更新到了新发布的 xCode 6 GM。当我现在尝试构建我的应用程序时,我收到一个编译器错误,说我的一个处理表的 View Controller “不符合协议(protocol) UITableViewDataSource”。之前一切正常(使用 xCode 6 Beta 5)

根据文档,该协议(protocol)需要两种方法:

– tableView:cellForRowAtIndexPath: 必需的方法

– tableView:numberOfRowsInSection: 必需的方法

它们都实现了:

 func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return feed!.count
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
println("HashtagDetailViewController: tableView - cellForRowAtIndexPath called")

let cell = tableView.dequeueReusableCellWithIdentifier("postCell", forIndexPath: indexPath) as PostTableCell
cell.loadItem(feed!.toArray()[indexPath.row])
return cell
}

我错过了什么?是否有文档中没有的新必需方法?谢谢你的帮助

最佳答案

在最新的 beta 版本中,许多 Swift 签名在使用可选项时发生了变化。因此,您现有的实现成为重载的本地方法,而不是协议(protocol)方法的实现。如果它是协议(protocol)中的必需方法,您将收到这些消息,因为编译器假定您尚未实现所需的方法。

这是一个小麻烦,但如果您在此类协议(protocol)中实现了可选方法的实现,并且已经更改了它们的签名,那就更加危险了。您不会收到任何编译器警告,并且您认为实现了协议(protocol)方法的方法将永远不会被调用。

您必须手动检查每个此类现有实现,以确保您的代码不会发生上述情况。

执行此操作的最简单方法是将光标放在每个此类方法标题中,因为您通常会在该方法的侧窗口中获得快速帮助。如果它被正确键入为协议(protocol)方法,您将在最后定义它的框架的快速帮助中看到该方法的描述。如果它由于签名差异而成为本地方法,您将不会在“快速帮助”窗口中看到任何描述,而是相关方法的列表,以及更多说明它是在该本地文件中定义的行。

在这样的框架更改之后,我不知道有什么方法可以阻止手动检查代码中每个现有的可选实现。

协议(protocol)略有改变:

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

就是现在:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

关于ios - 切换到 xcode 6 GM - 突然 Controller 不再符合 UITableViewDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25762709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com