呈现新的视图控制器.选项卡式图标消失



我正在处理一个选项卡式应用程序的项目。我的主页上有一个按钮,可以转到第二个选项卡式页面,但是当它加载时,它会删除底部的选项卡。如何防止这种情况发生?我的代码:

func manageButtonPressed() {
let NVC:SecondViewController = SecondViewController()
self.presentViewController(NVC, animated: true, completion: nil)   
}

替换:

self.presentViewController(NVC, animated: true, completion: nil)

跟:

self.tabBarController?.selectedIndex = 1

这假设您的主页按钮位于选项卡栏的第一个选项卡按钮的索引 0 上,而第二个 VC 位于索引 1 的第二个选项卡上。您可以根据选项卡栏的位置更改索引。

你想在 uinavigationcontroller 中使用 showViewController 方法。

因此,在调用 presentViewController 的视图的主情节提要中,您需要添加一个 UINavigationController。 然后,您可以在视图中调用

 self.navigationController.showViewController(NVC, sender: self)

然后它会将视图添加到导航堆栈的顶部,并将位于选项卡栏下方

最新更新