如何将可扩展表格菜单中的菜单名称“加拿大”链接到名为“加拿大”的新 View Controller ,然后将菜单名称“丹麦”链接到 Xcode 中名为“丹麦”的 View Controller ,依此类推-项目?
这是我的代码和一些图片。
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/