【发布时间】:2020-04-15 22:32:33
【问题描述】:
这是我的 tableViewController,我在其中调用 tabbedView,但是我在这一行遇到异常 let viewController = segue.destination as! EViewController 异常是:
Could not cast value of type 'UITabBarController' (0x7fff897a2cd8) to 'Test.EViewController'
这很奇怪,因为 EViewController 是 UIViewController 而不是 UITabBarController
EviewController 是 TabbedViewController 中的第一个 ViewController,我应该调用父控制器吗?我该怎么做?我想将数据传递给 tabbedViewController
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedName = (self.tableView.cellForRow(at: indexPath)?.textLabel?.text)!
performSegue(withIdentifier: “menu”, sender: self)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.names.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = names[indexPath.row]
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == “menu”) {
let viewController = segue.destination as! EViewController
}
}
}
【问题讨论】: