ios - 类型 'ProfilesTableViewController' 不符合 Xcode 6 GM 种子中的协议(protocol) 'UITableViewDataSource'

标签 ios uitableview swift xcode6

今天我迁移到 Xcode 6 GM 种子,现在我得到以下错误:

Type 'ProfilesTableViewController' does not conform to protocol 'UITableViewDataSource'.

我已经覆盖了 numberOfRowsInSectioncellForRowAtIndexPathnumberOfSectionsInTableView
事实上,直到今天一切正常。我注意到,当我删除 UITableViewDataSource 时,一切正常,没有发生任何错误。那么 .. 是否有必要再使用“UITableViewDataSource”,或者只是覆盖其中的函数?

最佳答案

这段代码编译得很好:

class ProfileTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {


override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

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

    let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("foo", forIndexPath: indexPath) as UITableViewCell

    return cell
}
}

因此,您绝对可以子类化 UITableViewController 并定义其 UITableViewDataSource 协议(protocol)实现。

请注意,我使用的是 override 关键字,而且我没有使用自动展开的参数——也就是说,不是这样的:

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

这在之前的 Xcode 6 beta 中是正确的。

关于ios - 类型 'ProfilesTableViewController' 不符合 Xcode 6 GM 种子中的协议(protocol) 'UITableViewDataSource',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25767092/

相关文章:

iphone - 如何像 Interface Builder 一样调整 iOS UI 组件的大小

ios - 使用 imageView 调整图标大小

objective-c - NSSplitView 分隔线的起始位置

swift - Swift 有并发安全保证吗?

swift - 是否有理由为您创建/有权访问的类创建扩展?

ios - 从iPhone中获取二进制文件

ios - 有没有办法让两次点击手势识别器具有不同的点击次数

ios - 快速:调用 willDisplay

swift - 代表团无法在 subview 中快速工作

iphone - 使用 xib 加载单元时的表格 View 单元重新创建