2017-03-24 74 views
-1

的電池我寫了下面的代碼顯示與SWIFT 2表視圖列表, 我需要相同的代碼,但是Xcode中給了錯誤,此代碼添加的tableview文本

我定義:

var toDoList = [string]() 

,並在的tableview FUNC:

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ 
     let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell") 

     cell.textLabel?.text = toDoList[indexpath.row] 
     return cell 

    } 

Xcode中具有低於誤差TodoList的[indexpath.row]:

鍵入'UITableView!'沒有下標成員

需要在swift 3中更改哪些內容?

+0

您需要重新設置單元格。 –

+0

從這裏接受幫助回答http://stackoverflow.com/questions/25826383/when-to-use-dequeuereusablecellwithidentifier-vs-dequeuereusablecellwithidentifi –

+0

@agent_stack我該怎麼做? –

回答

0

你應該改變你的代碼:

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! YouCellSubclass 
+0

隊友我沒有任何問題:let cell = UITableViewCell(style:UITableViewCellStyle.default,reuseIdentifier:「cell」)line command and i problem in:cell.textLabel?.text = toDo [indexpath.row] –

+0

please help ,我 –

0

替換爲下面的代碼你的代碼和嘗試。

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ 
     let cell = tableView.dequeueReusableCell(withIdentifier: "cell") 

     cell.textLabel?.text = toDoList[indexpath.row] 
     return cell 

    } 
+0

我取代它,並得到錯誤 –

+0

@ s.Soroush複製粘貼你的錯誤 –

0

你應該改變你的字符串數組定義

來源:

var toDoList = [string]() 

要:

var toDoList = [String]() 
0

您應該更改下面的代碼行。
1.數組聲明(字符串,而不是字符串)。

var toDoList = [String]() 

2.內置tableview委託方法。

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! YourCustomCellClass