2017-07-25 16 views
0

這是我的代碼:分配一個值超出數組的數組,採用部分在Xcode

let serviceBonnen = [[1,2,3],[4,5,6],[7,8,9]] //not real data 


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("NameCell", forIndexPath: indexPath) 
    cell.textLabel!.text = serviceBonnen[section][indexPath.row] 
    return cell 
} 

但它給我一個錯誤在「節」點在這行代碼:

cell.textLabel!.text = serviceBonnen[section][indexPath.row] 

有人知道爲什麼這不會編譯,什麼是一個適當的解決方案?

+1

你需要閱讀的錯誤信息,或至少它給我們。 @Miknash是否找到了它,但通常我們可以幫助你理解錯誤信息,如果你沒有。 – Larme

回答

2

您需要使用sectionindexPath

indexPath.section 

你行應該是這樣的:

cell.textLabel!.text = serviceBonnen[indexPath.section][indexPath.row] 
+0

非常感謝,它的工作 –

+0

太棒了。不要忘記接受答案是正確的:) – Miknash