我试图以编程方式呈现一个 UITableViewController
和一个嵌入其中的 UINavigationController
。但是,它会在没有导航 Controller 的情况下显示。我该如何解决这个问题?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MyTableViewController *myt = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"mytableviewControllerID"];
UINavigationController *nav = ((UINavigationController*)myt);
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
最佳答案
你的错误是在做
UINavigationController *nav = ((UINavigationController*)myt);
这不会将您的 Controller 嵌入到导航 Controller 中。您只是将 Controller 转换为导航 Controller 。
试试这个:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MyTableViewController *myt = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"mytableviewControllerID"];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:myt];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
关于ios - 导航到嵌入了 UINavigationController 的 UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40027587/