2016-10-13 70 views
0

我試圖以編程方式呈現嵌入到它的UITableViewControllerUINavigationController。但是,它在沒有導航控制器的情況下顯示。我該如何解決這個問題?導航到嵌入UINavigationController的UITableViewController

- (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; 

} 

回答

1

自己的錯誤做

UINavigationController *nav = ((UINavigationController*)myt); 

這並不嵌入您在導航控制器控制器。您只需將您的控制器投射到導航控制器即可。

試試這個:

- (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; 

} 
相關問題