【发布时间】:2020-12-26 05:36:17
【问题描述】:
我正在做一个项目,该项目没有故事板,它只有一个带有自己的类的 xib 文件的视图,问题是:如何在这些 xib 视图之间导航? 还是可以将它们嵌入到导航控制器中?
我尝试了这段代码,但什么也没发生?
let NC = UINavigationController()
@IBAction func showUserProfile(_ sender: Any) {
print("show Profile")
let vc = UserProfile(
nibName: "UserProfile",
bundle: nil)
NC.pushViewController(vc,
animated: true )
}
这是在应用委托中
let mainView = BlockListViewController(nibName: "BlockListViewController", bundle: nil)
window?.addSubview(mainView)
let navigationControll = UINavigationController(rootViewController: mainView)
self.window?.rootViewController = navigationControll
self.window?.makeKeyAndVisible()
当事件发生时,我会尝试使用它进行导航
self.navigationController?.pushViewController(UserProfile(), animated: true)
【问题讨论】:
-
你不能在 VC 中添加这些视图并进行导航
-
如何在它们之间导航?我将一个设置为初始视图控制器,但我需要在这些 xib 视图之间导航
-
检查我的答案并更新有关此评论的解决方法
标签: ios swift navigation