2015-11-10 89 views
0

我得到了一個錯誤,指出消息「無法找到該接受提供的參數‘下標’超載」我怎麼能解決這個問題錯誤-swift-泰伯維-custome細胞

//declaration of children 
var children = [Child]() 

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

     let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:"Cell") 
     cell.textLabel?.text = children[indexPath.row] //error appears here 
     return cell 

    } 
+0

是什麼'children'類型的類型? – vadian

+0

它是一個子類型的數組 – batool

+0

可能是可選的,不是嗎?不要這樣做。對於表視圖數據源,聲明數組始終是非可選的空數組,如'var children = [Child]()' – vadian

回答

0

children可能是不指定爲一個字符串數組。您需要顯式轉換children[indexPath.row]爲String,或改變children

cell.textLabel?.text = children[indexPath.row] as! String 
+0

我怎樣才能將數組轉換成字符串 – batool

+0

更新後的答案。 –

+0

謝謝安迪,但我很抱歉,同樣的錯誤仍然出現 – batool