【发布时间】:2023-03-26 14:03:01
【问题描述】:
非常简单的场景,有很多关于此的帖子,但我仍然卡住了。我有一个嵌入在UINavigationController 中的UITableView 有一个最终的UIViewController,应该在选择UITableViewCell 时显示。当我将所有这些连接起来时,行选择没有任何反应。
我可以获得由 usind didSelectRowAtIndexPath 呈现的详细视图,并通过其 ID 引用 segue。但是,当我这样做时没有返回按钮。
类 MainViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableview: UITableView!
var configJson: JSON = []
var config: [Tab] = []
override func viewDidLoad() {
super.viewDidLoad()
parseConfig()
}
func parseConfig() {
let configParser = ConfigParser(configJson: configJson)
config = configParser.parse()
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.config.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let tab = self.config[indexPath.row]
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
cell.textLabel?.text = tab.title
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "contentSegue", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "contentSegue") {
let nextVC = segue.destination as? ContentViewController
let indexPath = self.tableview.indexPathForSelectedRow
let tab = self.config[(indexPath?.row)!]
nextVC?.tab = tab
}
}
}
其他几点说明:
1. 我的单元格标识符在 IB 中设置为“单元格”
2. 我的 segue 在 IB 中设置为“show”,标识符为“contentSegue”
3. segue 是从原型单元到内容视图控制器。
我完全不知所措。任何人都可以帮忙吗?谢谢。
【问题讨论】:
-
请提供您的下一个视图控制器代码
-
目前还没有。这只是一个空的 viewDidLoad() 方法。
-
尝试删除你的segue并重新创建它,有时它会有所帮助,也许你是从UITabeView或Cell创建的,而不是ViewController
-
谢谢。我已经试过几次了。
-
你在故事板中做了什么样的转场?
标签: ios uitableview swift3 uinavigationcontroller