0

I am trying to create a TableView with two headers (Account,Support) and with text titles in sections.But I am getting errors

I followed answer from this question: How do I populate two sections in a tableview with two different arrays using swift?

Errors: enter image description here and: enter image description here

This is my code:

 var myTitles = [["Delete current photo","Change profile picture","Change username","Change password"],["Help","Report a problem"]]

let headerTitles = ["Acount", "Support"]

override func viewDidLoad() {
    super.viewDidLoad()

}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return myTitles[section].count
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return 3 //This is not complete yet.
}

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    if section < headerTitles.count {
        return headerTitles[section]
    }

    return nil
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("settingCell", forIndexPath: indexPath)

    cell.textLabel?.text = myTitles[indexPath.section][indexPath.row]

    return cell
}
Community
  • 1
  • 1
0ndre_
  • 3,577
  • 6
  • 26
  • 44

1 Answers1

0

First of all, where are you getting the section value here:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return myTitles[section].count
}

Change that to just return myTitles.count.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
royherma
  • 4,095
  • 1
  • 31
  • 42