2014-10-04 16 views
4

重寫UITableViewDelegatetableView:cellForRowAtIndexPath:導致以下編譯錯誤:與選擇重載方法有不兼容的類型 - 斯威夫特

Overriding method with selector 'tableView:cellForRowAtIndexPath:' has incompatible type '(UITableView!, NSIndexPath!) -> UITableViewCell!'

當前實現覆蓋功能是:

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! 
{ 
    let cell = tableView.dequeueReusableCellWithIdentifier("cellIdent", forIndexPath: indexPath) as UITableViewCell 

    // Configure the cell... 

    return cell 
} 

是什麼原因造成錯誤以及如何解決?

+0

嘗試僅刪除 「覆蓋」。如果這不起作用,請發佈您的整個班級。 – 2014-10-04 04:56:36

回答

5

UITableViewDataSource刪除implicit optional type。檢查有沒有可選的tableViewindexPath。還刪除override爲你實現方法,你不需要寫override

替換爲以下方法

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 
}