2017-02-28 43 views
0

我把在我的ViewController。我做了GroupTable。所以,我選擇表格並在屬性檢查器中選擇樣式「分組」。ViewController中的GroupTable與Swift 3

var TableArray = [["Home","Apple","Orange","Pineapple"],["Flour","Cake Flour"]] 

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 

    return TableArray.count 

} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    debugPrint(TableArray[section].count) 

    return TableArray[section].count 

} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withIdentifier: TableArray[indexPath.section][indexPath.row], for: indexPath) as UITableViewCell 

    cell.imageView?.image = menuIconImage[indexPath.row] 
    cell.textLabel?.text = TableArray[indexPath.section][indexPath.row] 
    cell.selectionStyle = UITableViewCellSelectionStyle.blue 
    tableView.rowHeight = 56.0; 

    return cell 

} 

當我運行應用程序時,表格只顯示「Home」,「Apple」,「Orange」,「Pineapple」。
它確實不顯示「麪粉」,「蛋糕麪粉」。
我不知道問題出在哪裏。請幫幫我。

回答

1

方法numberOfSectionsInTableView是錯誤的,默認值爲1

雨燕3語法是:

func numberOfSections(in tableView: UITableView) -> Int { 
    return TableArray.count 
} 

根據命名規則變量名必須以小寫字母開頭。

+0

是bro @vadian。但是,我想要2個部分。一節包括 - >「家」,「蘋果」,「橙」,「菠蘿」。第二部分包括 - >「麪粉」,「蛋糕麪粉」。我怎樣才能做到這一點? bro –

+0

您正在使用錯誤的API。用我的答案中的方法替換你的方法。 – vadian

+0

Bro @vadian,你的代碼適合我...感謝百萬兄弟! :) :) :) –

相關問題