【问题标题】:TableView didselectrow not pushing another viewTableView didselectrow 没有推送另一个视图
【发布时间】: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)
    }

代码看起来不错,情节提要 ID 也正确,但是当我单击单元格并且没有操作时它没有推送,控制台响应也很好

断点没有问题!

我的故事板

【问题讨论】:

  • vc.data = data[indexPath.row]这一行添加断点并检查
  • else { return } 是否调用了returnself.navigationController?:你有navigationController吗? self.navigationController? 是零吗?
  • 确保您将 SecAdsViewController 嵌入到 navigationController 中
  • @Larme 是的,它嵌入到导航控制器中
  • 所以self.navigationController? 是零?那么你期望它如何工作呢?您可以使用present(animated:completion:),但这是一个模态演示。是否需要导航控制器取决于您。取决于您的用户体验/用户界面。

标签: ios swift uitableview uiviewcontroller uinavigationcontroller


【解决方案1】:

正如您在评论中提到的,最好的解决方案是创建一个新的故事板。 试试这个

let storyboard = UIStoryboard(named: "Sections", bundle: "nil")
guard let vc = storyboard.instantiateViewController(withIdentifier: "SecAdsViewController") as? SecAdsViewController else { return }
vc.data = data[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)

此解决方案假定您在 Sections 情节提要中没有 NavigationController,因为您在其他情节提要中已经有 NavigationController,所以无论如何您都不希望这样做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    相关资源
    最近更新 更多