Ok so I have been scouring this site to find a solution to my problem. I have found one but for some reason by code just won't work the way intended. My goal is to have a table view with sections in it. Under each section is a different amount (such as 1 in one section and 3 cells in another section) of cells in each section.
Here is my code
import UIKit
class cat1: UIViewController, UITableViewDelegate, UITableViewDataSource {
let proc = [["this"], ["Ye", "it", "will"]]
let infor = [["info 1"] , ["info 3", "info 2" , "info 4"]]
let arrayforsec = [ "test", "testtt"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return proc[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as UITableViewCell
let cellText = proc[indexPath.section][indexPath.row]
let descriptiontxt = infor[indexPath.section][indexPath.row]
cell.detailTextLabel?.numberOfLines = 0
cell.detailTextLabel?.lineBreakMode = .byWordWrapping
cell.textLabel?.text = cellText
cell.detailTextLabel?.text = descriptiontxt
return (cell)
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section :Int) -> String?{
return arrayforsec[section]
}
func numberOfSectionsInTableView(in tableView: UITableView) -> Int {
return proc.count
}
}
My goal is to have 2 diffferent headers, test and testtt
test will have the cell with the title this and the subtitle info 1 and so on
What am I messing up?
here is the solution I consulted :How do I populate two sections in a tableview with two different arrays using swift?
(the response w/ 40 upvotes)