Reputation: 43
Overriding UITableViewDelegate
's tableView:cellForRowAtIndexPath:
is causing the following compile error:
Overriding method with selector 'tableView:cellForRowAtIndexPath:' has incompatible type '(UITableView!, NSIndexPath!) -> UITableViewCell!'
The current implementation of the override function is:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdent", forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
return cell
}
What is causing the error and how can it be fixed?
Upvotes: 4
Views: 1305
Reputation: 21
Try this:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
This may help: Overriding method with selector '***' has incompatible type '****' parse
Upvotes: -1
Reputation: 37189
Remove implicit optional type
.Check in UITableViewDataSource
there is no optional for tableView
,indexPath
.Also remove override
as you implementing the protocol
methods you do not need to write override
Replace with below method
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
//the error is on the line oboe... Overriding method with selector 'tableView:cellforRowAtIndexPath:'has incompatible type '(TableView, NSIndexpath) -. UITableViewCell!'
{
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdent", forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
return cell
}
Upvotes: 5