gpt4 book ai didi

swift - 导航栏未快速显示在 TableviewController 上

转载 作者:行者123 更新时间:2023-11-30 10:06:12 26 4
gpt4 key购买 nike

我的项目中有一个 CollectionView 正在运行,并且 collectionViewController 使用自定义 Segue 连接到另一个 TableView ,如下所示。

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
selectedMenuItem = indexPath.row

//Present new view controller
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main",bundle: nil)

var destViewController : UINavigationController


switch (indexPath.row) {
case 0:
destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("NewTableView") as UINavigationController
break
default:
destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("NewTableView") as UINavigationController
break
}
self.presentViewController(destViewController, animated: true, completion: nil)


}

上面的代码成功填充了我的 NewTableview,但 tableview 完全缺少导航栏。

到目前为止我的尝试如下......

  • 我将新的 navigationController 嵌入到 collectionView 结果保持不变。

  • 我将新的 navigationController 嵌入到 NewTableView 结果保持不变。

  • 我尝试使用自定义导航按钮操作方法展开segue方法。所以我将导航栏项目和按钮插入到 View 中并且方法有效,但是当按下导航栏按钮时它会奇怪地工作,它将我带到我的主 Collection View Controller 就是我的东西。但是我有另一个后退按钮出现在 Collection View rowindex 项目名称中。当我按下该按钮时,它带我回到 NewTableView,就像循环一样。

我不知道我错过了什么(任何委托(delegate)方法)。我注意到 newTableView 数据从底部加载动画......

我想知道是否有任何方法可以通过编程方式将导航与后退按钮行为结合起来......

提前致谢......

最佳答案

您必须实例化导航 Controller ,而不是 Storyboard中的实际 View Controller 。因此,您应该向 UINavigationController 添加一个标识符,而不是实例化 NewTableView (您想要嵌入导航 Controller 的 View Controller ),以便实例化它而不是 View Controller 本身。

想象一下,您重用了 NewTableView Controller ,它不需要导航 Controller 作为其根,iOS 如何知道这一点?因此,向您的托管 UINavigationController 添加一个标识符并实例化它。导航 Controller 对默认显示的 rootViewController 有根依赖,因此您只需要显示 UINavigationControllerNewTableView Controller 将根据它与导航 Controller 的依赖关系来显示。

关于swift - 导航栏未快速显示在 TableviewController 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35822169/

26 4 0