如何在视图上显示UINavigationController [英] How to show UINavigationController on view

查看:108
本文介绍了如何在视图上显示UINavigationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.

    [window addSubview:viewController.view];
    MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:@"MainPage" bundle:nil];
    UINavigationController *nav_obj = [[UINavigationController alloc] initWithRootViewController:overviewViewController ];

    [self.viewController presentModalViewController:nav_obj  animated:YES];
    [overviewViewController release];
    [self.window makeKeyAndVisible];

    return YES;
}

此代码显示导航控制器的蓝色条,但没有按钮。似乎是UINavigationController被分配为空。
谁知道问题是什么?

This code shows the blue bar of navigation controller, but no buttons on it.It seems like to be that the UINavigationController allocated as empty. Who knows what problems is?

UPD:存档 http://www.mediafire.com/?lbjjvl6fcue2q18
请帮帮我,我是Objective-c的新手

UPD:Archive http://www.mediafire.com/?lbjjvl6fcue2q18 Please help me, I'm new in objective-c

推荐答案

使用 UINavigationController 的正确方法是 push 查看控制器到它。这样它们将被堆叠,并且当它是大小写时(即,当你实际上可以返回到前一个控制器时)导航栏将用后退按钮填充。您可以通过定义您推送的控制器的标题来控制后退按钮中显示的标签。

The correct way to use a UINavigationController is to push view controllers on to it. That way they will be stacked and the navigation bar will be populated with a back button when it is case (i.e., when you can actually go back to a previous controller). You control the label that appears in the "back" button by defining the title of the controllers you push.

如果您需要,可以使用另一个答案(明确设置按钮)显示右侧按钮。

The technique shown in another answer (setting explicitly the button) is useful with defining the right button, if you ever need one.

你可以尝试使用此代码:

You could try with this code:

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

    MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:@"MainPage" bundle:nil];
    UINavigationController* navigation = [[UINavigationController alloc] init];
    [navigation pushViewController:overviewViewController animated:NO];
    [overviewViewController release];

    [window addSubview:[navigation view]];
    [self.window makeKeyAndVisible];

    return YES;
}

而不是:

    UINavigationController* navigation = [[UINavigationController alloc] init];
    [navigation pushViewController:overviewViewController animated:NO];

你也可以使用 initWithRootController ,但是要显示你如何推动视图控制器的一般情况我更喜欢这个。

you could also use initWithRootController, but to display the general case of how you push a view controller I preferred this one.

请注意,由于你只推动一个根控制器,你应该看不到后面的按钮。那一刻,但是如果你按下第二个视图控制器,它就会出现。

Notice that since you are pushing just a root controller, you should see no back button at the moment, but if you push a second view controller, then it will appear.

编辑:我看了你的项目。你应该尝试和做的总结:

I gave a look at your project. Summary of what you should try and do:


  1. 你在NIB中需要的对象:文件所有者(UIApplication),第一响应者, FBFun App Delegate(iVkAppDelegate),Window(UIWindow);删除其余部分;

  1. objects you need in your NIB: File's Owner (UIApplication), First Responder, FBFun App Delegate (iVkAppDelegate), Window (UIWindow); remove the rest;

文件的所有者代理出口是FBFun App Delegate;

File's owner delegate outlet is FBFun App Delegate;

FBFun App Delegate窗口是Window。

FBFun App Delegate window outlet is Window.

通过这个简单的设置(或多或少你有),使用此代码:

With this simple setup (more or less what you have), use this code :

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

     UINavigationController* navigation = [[UINavigationController alloc] init];

     //--    MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:@"MainPage" bundle:nil];
     iVkViewController *overviewViewController = [[iVkViewController alloc] init];
 overviewViewController.title = @"First";
     [navigation pushViewController:overviewViewController animated:NO];

     iVkViewController *overviewViewController2 = [[iVkViewController alloc] init];
 overviewViewController2.title = @"Second";
     [navigation pushViewController:overviewViewController2 animated:NO];

    [overviewViewController release];
    [window addSubview:[navigation view]];
    [self.window makeKeyAndVisible];

    return YES;
}

在上面的代码中,正如您所注意到的,我实例化了两次 iVkViewController 只是为了让第二个控制器进入导航器。

In the code above, as you notice, I instantiated twice your iVkViewController just to have a second controller to push onto the navigator.

请从模拟器中删除现有应用程序,然后运行此应用程序以查看导航栏是否已正确创建,您可以从第二个控制器返回第一个。

Please, delete your existing app from the simulator, and the run this in order to see that the navigation bar is correctly created and you can go back from the second controller to the first one.

我删除了MainPageDialog的使用,因为MainPage笔尖有很多问题。

I removed usage of MainPageDialog, because the MainPage nib has many problems.

但是我希望这个骨架足以让你继续发展。

But I hope this skeleton is sufficient for you to go forward with your development.

这篇关于如何在视图上显示UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆