【发布时间】:2018-02-12 14:46:59
【问题描述】:
我有基于 tableView 的幻灯片菜单。我还在 IB 上创建了标签栏。 标签栏上的第一项类似于主页。默认情况下,运行应用程序时该项目显示主屏幕。当从菜单中选择一项时,它应该在与主页相同的视图中打开。
//菜单项中负责选择主页标签栏项的部分代码
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
ContainerVC.tabBarViewController?.selectedIndex = 0
}
//分离视图控制器上的viewWillAppear函数
override func viewWillAppear(_ animated: Bool){
super.viewWillAppear(true)
let vc = self.storyboard?.instantiateViewController(withIdentifier: "DynNews")
self.navigationController?.pushViewController(vc!, animated: true)
}
这仅在启动应用程序时有效。后来应用程序只显示主页。这是因为标签栏只加载一次视图然后选择标签索引不会调用 viewWillAppear 但我不知道如何解决这个问题。
【问题讨论】: