今天我迁移到 Xcode 6 GM 种子,现在我得到以下错误:
Type 'ProfilesTableViewController' does not conform to protocol 'UITableViewDataSource'.
我已经覆盖了 numberOfRowsInSection
、cellForRowAtIndexPath
和 numberOfSectionsInTableView
。
事实上,直到今天一切正常。我注意到,当我删除 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/