2017-10-08 158 views
-2

我試圖使用表格視圖,並在FUNC: cellForRowAt我得到一個錯誤:Cannot convert value of type 'IndexPath.Type' to expected argument type 'IndexPath'無法將類型的價值「IndexPath.Type」預期參數類型「IndexPath」

我的代碼是:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cellDish:DishTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellDish", for: IndexPath) as! DishTableViewCell  
    return cellDish 
} 
+1

'for:indexPath'。使用參數'indexPath'小寫'i'而不是'IndexPath'類型。 – vacawama

+0

謝謝!有用 –

回答

0

問題是您的IndexPath參數。

您使用的是類而不是實例。正確的方法是:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cellDish:DishTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellDish", for: indexPath) as! DishTableViewCell  
    return cellDish 
} 
相關問題