Расширяемое меню таблицы для нового View Controller в Xcode - PullRequest
0 голосов
/ 18 января 2020

Как я могу связать имя меню «Canada» в моем меню расширяемой таблицы с новым View Controller с именем «Canada», а затем имя меню «Denmark» с View Controller с именем «Denmark» и так далее в моем Xcode -проект?

Вот мой код и несколько картинок.

enter image description here

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, ExpandableHeaderViewDelegate {

@ IBOutlet слабая переменная 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 ]

0 голосов
/ 18 января 2020

Извините, я не могу понять, где поставить этот код

0 голосов
/ 19 января 2020

Вот мое фото всех сбоев.

enter image description here

0 голосов
/ 18 января 2020
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
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...