【发布时间】:2021-04-23 17:50:32
【问题描述】:
我也在尝试从带有 tableview 的 viewcontroller 推送到带有 tableview 的另一个视图,
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("Clicke\(indexPath.row)")
guard let vc = storyboard?.instantiateViewController(withIdentifier: "SecAdsViewController") as? SecAdsViewController else { return }
vc.data = data[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)
}
【问题讨论】:
-
在
vc.data = data[indexPath.row]这一行添加断点并检查 -
else { return }是否调用了return?self.navigationController?:你有navigationController吗?self.navigationController?是零吗? -
确保您将 SecAdsViewController 嵌入到 navigationController 中
-
@Larme 是的,它嵌入到导航控制器中
-
所以
self.navigationController?是零?那么你期望它如何工作呢?您可以使用present(animated:completion:),但这是一个模态演示。是否需要导航控制器取决于您。取决于您的用户体验/用户界面。
标签: ios swift uitableview uiviewcontroller uinavigationcontroller