Ios 类型';ProfileStablevewController';不符合协议';UITableViewDataSource';在Xcode 6转基因种子中
今天我迁移到Xcode 6 GM seed,现在我遇到以下错误: 类型“ProfilesTableViewController”不符合协议 “UITableViewDataSource”Ios 类型';ProfileStablevewController';不符合协议';UITableViewDataSource';在Xcode 6转基因种子中,ios,uitableview,swift,xcode6,Ios,Uitableview,Swift,Xcode6,今天我迁移到Xcode 6 GM seed,现在我遇到以下错误: 类型“ProfilesTableViewController”不符合协议 “UITableViewDataSource” 我已将numberOfRowsInSection、cellforrowtaindexpath和numberofsection覆盖到tableview
我已将
numberOfRowsInSection
、cellforrowtaindexpath
和numberofsection覆盖到tableview
<事实上,直到今天一切都很顺利。我注意到,当我删除UITableViewDataSource
时,一切都正常工作,没有发生错误。所以是否有必要再使用“UITableViewDataSource
”,或者只是覆盖其中的函数?我的猜测是,至少基于错误,您没有实现所有功能。编辑:因为Xcode 6 beta
语法:
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!){
我们必须检查打开的桌面视图。所以我用了:
if let tblView = tableView {
//code
}
及
所以。。。为了不改变我的整个项目,我覆盖了如下函数:
override func tableView(tableView: UITableView?, didSelectRowAtIndexPath indexPath: NSIndexPath?){
override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
一切正常,除了我的更改导致ProfileTableViewController不符合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
协议实现
请注意,我使用的是override
关键字,而且我没有使用自动展开参数——即,不是这样的:
override func tableView(tableView: UITableView?, didSelectRowAtIndexPath indexPath: NSIndexPath?){
override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
这在以前的Xcode 6 Beta中是正确的。我恐怕要说这是错误的。请核对我的答案。事实是我们都是对的。。。因为你给我的例子来自SDK。。。但我需要对irder中sdk中的代码进行一点修改,以使用条件辅助。。。所以你的代码有效,我的答案中的代码也有效…:)