0
votes

How can I link the menu name "Canada" in my expandable table menu to a new View Controller named "Canada", and then the menu name "Denmark" to a View Controller named "Denmark" and so on in my Xcode-project?

Here is my code and some pictures.

enter image description here

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, ExpandableHeaderViewDelegate {

@IBOutlet weak var tableView: UITableView!

var sections = [
Section(genre: "North America",
        menytitel: ["USA", "Canada"],
        expanded: false),
Section(genre: "Europe",
        menytitel: ["Sweden", "Finland", "Denmark", "Ireland"],
        expanded: false),
Section(genre: "Africa",
        menytitel: ["Egypt", "Marocko"],
        expanded: false),

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell")!
cell.textLabel?.text = sections[indexPath.section].menytitel[indexPath.row]
return cell
3
pass section title to new viewController and in new viewcontroller's viewdidload method write self.title = "section titile". - Ruchi Makadia
Do you have ViewController of each of the Item names or you want to handle all items by one ViewController - Afsar edrisy

3 Answers

0
votes
class TestTableViewController: UITableViewController {
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        guard let section = sections[indexPath.section] as? Section,
            let title = section.menytitel[indexPath.row] as? String else { return }

        switch title {
        case title == "Denmark":
            let denmarkVC = UIViewController()
            present(denmarkVC, animated: true, completion: nil)
        default:
            break
        }
    }
}
0
votes

Sorry I can't figure out where to put this code

0
votes

Here is my picture of all the failures.

enter image description here