ios - 导航到嵌入了 UINavigationController 的 UITableViewController

标签 ios objective-c iphone uinavigationcontroller appdelegate

我试图以编程方式呈现一个 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/

相关文章:

ios - 从cocos2d应用播放iTunes歌曲预览

ios - Swift - 执行 segue 时 Viewcontrollers 不会取消初始化

ios - 如何以编程方式从 Storyboard中的 View Controller 加载弹出窗口。

objective-c - iPhone/Objective-C : Can't delete a file

IOS:一个 IBAction 用于多个按钮

ios - 从 UIWebView 捕获信息

ios - 无法访问 UICollectionViewCell 中的 UITextField

ios - 将 Parse.com 导入 Xcode 的 Prefix.pch 的导入类生成错误

ios - 403 错误 - 这是一个错误。错误 : disallowed_useragent

ios - 使用drawRect延迟加载UIViews : drawing