ios - 可将表格菜单扩展到 Xcode 中的新 View Controller

标签 ios swift uitableview uikit

如何将可扩展表格菜单中的菜单名称“加拿大”链接到名为“加拿大”的新 View Controller ,然后将菜单名称“丹麦”链接到 Xcode 中名为“丹麦”的 View Controller ,依此类推-项目?

这是我的代码和一些图片。

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

最佳答案

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
        }
    }
}

关于ios - 可将表格菜单扩展到 Xcode 中的新 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59798851/

相关文章:

swift - 匹配元组范围内的整数元组

uitableview - Selenium Webdriver - 获取表数据

ios - 如何以编程方式将 UIImageView 缩放到固定宽度和灵活高度?

ios - Swift - 如何让文本字段在测验中识别多个正确答案?

ios - 检测 IAP 取消

swift - iOS 9 中可滑动的表格 View 单元格

ios - 将自定义的 UITableViewCell 导出到 UIImage

iphone - 一次安装多个图标?

ios - PromiseKit for In Loop 实现时

swift - 列出 AWS S3 存储桶中的所有对象