我有.xib(不是.storyboard)文件,其中我有UIView,里面也有UITableView。所以,现在我想添加导航功能,但我不能像本教程中那样嵌入导航控制器http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/ 因为我使用.xib而不是.storyboard。如何在我的应用中添加导航功能?
答案 0 :(得分:6)
您可以通过编程方式添加它。
例如:
// Swift
let navController = UINavigationController(rootViewController: Your View Controller)
// Obj-C
UINavigationController *navControler = [[UINavigationController alloc] initWithRootViewController: YourViewController];
然后根据您计划显示的时间推送/显示导航控制器。
看过这个教程后,我假设您要将导航控制器显示为第一个屏幕,在这种情况下,您可以像这样将它添加到AppDelegate
。
// Swift
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.makeKeyAndVisible()
self.window?.rootViewController = navController
// Obj-C
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
[self.window setRootViewController: navController];