加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iOS:Xcode 4.2和导航控制器

发布时间:2020-12-14 17:53:19 所属栏目:百科 来源:网络整理
导读:在XCode 4.2中,当我选择“新项目”并选择“单一视图应用程序”但现在我想添加一个导航控制器.我在 Xcode 4.2中可以做些什么呢? (没有故事板) 解决方法 除非您将UINavigationController添加到另一个用于不同导航方法的UIViewController,即UISplitViewControl
在XCode 4.2中,当我选择“新项目”并选择“单一视图应用程序”但现在我想添加一个导航控制器.我在 Xcode 4.2中可以做些什么呢? (没有故事板)

解决方法

除非您将UINavigationController添加到另一个用于不同导航方法的UIViewController,即UISplitViewController或UITabBarController,我建议将UINavigationController添加到AppDelegate中的应用程序窗口,然后添加包含您视图的UIViewController.

如果要将UINavigationController添加为主UIViewController,则可以通过AppDelegate中的以下方法以编程方式轻松执行此操作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

我要添加的代码是:

UINavigationController *navcon = [[UINavigationController alloc] init];
[navcon pushViewController:self.viewController animated:NO];
self.window.rootViewController = navcon;

现在,在你的AppDelegate.m中它应该如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
    } 
    else
    {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
    }
    UINavigationController *navcon = [[UINavigationController alloc] init];
    [navcon pushViewController:self.viewController animated:NO];
    self.window.rootViewController = navcon;
    [self.window makeKeyAndVisible];
    return YES;
}

您可以通过查看UINavigationController Apple Documentation及其示例项目来进一步了解如何利用UINavigationController,您可以从同一文档页面下载这些项目.示例项目将帮助您掌握使用UINavigationController的各种方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读