The override method with the selector is of an incompatible type - Swift

Overriding UITableViewDelegate tableView:cellForRowAtIndexPath:causes the following compilation error:

The overriding method with the selector 'tableView: cellForRowAtIndexPath:' has an 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 causes the error and how can it be fixed?

+4
source share
2 answers

Remove implicit optional type.Check in UITableViewDataSourceno options tableView, indexPath. Also remove overridewhen implementing methods protocolthat you do not need to writeoverride

Replace 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
}
+5
source

Try the following:

func tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) → UITableViewCell {

: '***' '****' parse

-1

All Articles