导航到嵌入了UINavigationController的UITableViewController

时间:2016-10-13 17:40:02

标签: ios objective-c iphone uinavigationcontroller appdelegate

我正在尝试以编程方式呈现UITableViewControllerUINavigationController。但是,它会在没有导航控制器的情况下显示。我该如何解决这个问题?

- (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 个答案:

答案 0 :(得分: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;

}