【问题标题】:PageMenu pod presents Modal segue instead of Push seguePageMenu pod 呈现 Modal segue 而不是 Push segue
【发布时间】:2017-06-19 18:01:08
【问题描述】:

这个问题涉及到

我知道这个问题可能与其他问题非常相似。但我一直无法使用某些答案来解决我的问题。

这是我的故事板的外观:

viewController 有一个段控制,它控制两个视图控制器。我现在想转至 DetailViewController,但它显示为隐藏 tabBar 和导航栏的模态转场。

我已经尝试删除并重新创建 segue,因为答案中的一些建议但它没有解决任何问题。有什么人可以建议或指导我吗?

编辑:

在测试了 pod 提供的演示后,我能够概述我正在努力解决的问题。我已经实现了几乎相同的相同方法。唯一的区别是我的 PageMenu 方法不像演示那样使用 nib 文件。

在我的 tableView 委托中,我试图将配方数据传递给 DetailView。这就是我的 prepareForSeguedidSelect 的外观:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    performSegue(withIdentifier: "detail", sender: recipe)

}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "detail" {
        let vc = segue.destination as! DetailViewController
        let indexPath = tableView.indexPathForSelectedRow!
        vc.recipe = RecipeManager.shared.recipes[indexPath.row]

    }
}

这是 demo 的 didSelect

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let newVC : UIViewController = UIViewController()
    newVC.view.backgroundColor = UIColor.white
    newVC.title = "Favorites"

    parentNavigationController!.pushViewController(newVC, animated: true)
}

在将它与演示进行比较时,我很难理解在哪里实施 parentNavigationController!.pushViewController(newVC, animated: true),我相信这会解决我的问题。

【问题讨论】:

  • 你说的“viewController有一个segmentControl控制两个viewController”是什么意思?您是否使用它将一个或另一个表视图加载到容器视图中?
  • 您是否尝试将嵌入在 UINavigationController 中的视图控制器推送到另一个 UINavigationController 上?
  • @DonMag 基本上我正在使用一个名为“PageMenu”的 pod,它使用 viewController 执行分段操作,您可以在其中滑动到不同的页面,就像您在 Instagram 上看到的那样。
  • @suhit 不确定您的意思。如您所见,我只有一个 UINavigationController。我要做的就是继续使用 DetailViewController。
  • @Chace - 好的...很可能,您的“PageMenu”窗格导致您的 segue 被放置在导航控制器堆栈的外部。您需要弄清楚视图层次结构是如何排列的,并确保与DetailVC 的转接正在完成来自 ViewController 而不是来自子VC 作为一部分“页面菜单”

标签: ios segue uistoryboardsegue


【解决方案1】:

假设您像他们在演示中所做的那样实现了parentNavigationController,那么您几乎一切就绪。

删除您现有的 Segue - 您不会使用它。

给您的 DetailViewController 一个 Storyboard ID - 例如“DetailVC”

更改代码以实例化 DetailVC 并将其推送到父导航控制器

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if let vc = self.storyboard?.instantiateViewController(withIdentifier: "DetailVC") as? DetailViewController {
        vc.recipe = RecipeManager.shared.recipes[indexPath.row]
        parentNavigationController!.pushViewController(vc, animated: true)
    }

}

【讨论】:

  • 谢谢你,它工作得很好!我只是想知道,有没有办法像替换导航栏一样隐藏 tabBar,或者这是一个不同的问题。
  • 不确定您的导航层次结构是如何设计的,但有几种方法可以隐藏标签栏。看看这里的一些答案:stackoverflow.com/questions/37040313/… ...如果这不适合您的情况,我希望您可以通过搜索找到一些东西。
猜你喜欢
  • 2016-06-27
  • 2018-10-28
  • 1970-01-01
  • 2012-03-12
  • 1970-01-01
  • 2012-01-15
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
相关资源
最近更新 更多