0

I put Table in my ViewController. I made GroupTable. So, I select the table and choose "Grouped" in style in Attribute Inspector.

 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

} 

When I run the app, the table only shows "Home","Apple","Orange","Pineapple".
It does not show "Flour", "Cake Flour".
I don't know where the problem is. Please help me.

May Phyu
  • 895
  • 3
  • 23
  • 47

1 Answers1

1

The method numberOfSectionsInTableView is wrong, the default value is 1.

The Swift 3 syntax is:

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

According to the naming convention variable names should start with a lowercase letter.

vadian
  • 274,689
  • 30
  • 353
  • 361
  • Yes bro @vadian. But, I want 2 sections. One Section includes --> "Home","Apple","Orange","Pineapple". Second Section includes --> "Flour", "Cake Flour". How can I do this? bro – May Phyu Feb 28 '17 at 09:31
  • You are using the wrong API. Replace your method with the method in my answer. – vadian Feb 28 '17 at 09:32
  • Bro @vadian, your code works for me... Thanks a million bro !!!! :) :) :) – May Phyu Feb 28 '17 at 09:36