Type 'ProfilesTableViewController' does not conform to protocol 'UITableViewDataSource' in Xcode 6 GM seeds
Today I upgraded to Xcode 6 GM semester and now I am getting the following error:
The "ProfilesTableViewController" type does not conform to the 'UITableViewDataSource' protocol.
I have overridden numberOfRowsInSection
, cellForRowAtIndexPath
and numberOfSectionsInTableView
.
In fact, everything has worked well until today. I noticed that when I uninstall UITableViewDataSource
everything works fine and no errors occur. So .. do I need to use ' UITableViewDataSource
' or just override functions from it?
source to share
This code compiles fine:
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
}
}
So, you can define a subclass UITableViewController
and define its protocol implementation UITableViewDataSource
.
Note that I am using the keyword override
and also that I am not using auto-expanded arguments, i.e. not this way:
override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
which was correct in previous Xcode 6 beta releases.
source to share
EDIT: due to the syntax Xcode 6 beta
:
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!){
We needed to check the expanded tableView. So I used:
if let tblView = tableView {
//code
}
and
if let theIndexPath = indexPath {
//code
}
So ... in order not to change my whole project, I redefined functions like this:
override func tableView(tableView: UITableView?, didSelectRowAtIndexPath indexPath: NSIndexPath?){
and everything works fine except that with my changes the ProfileTableViewController doesn't match UITableViewDataSource
and I had to remove the datasource from the class definition.
source to share