0

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
2
  • pass section title to new viewController and in new viewcontroller's viewdidload method write self.title = "section titile". Commented Jan 18, 2020 at 8:54
  • Do you have ViewController of each of the Item names or you want to handle all items by one ViewController Commented Jan 18, 2020 at 9:09

3 Answers 3

0
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
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

Here is my picture of all the failures.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.