0

在我的项目中,导航栏只出现在 rootview(homeview) 中,我想在所有视图中启用导航栏?这是我的代码?我应该为此做些什么改变

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.window.rootViewController =navigationController;
[self.window addSubview:[navigationController view]];
[self.window makeKeyAndVisible];
return YES;
}

请帮我写代码?

4

5 回答 5

1

看到这个链接

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    navigationController =[[UINavigationController alloc] init];

    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [navigationController pushViewController:viewController2 animated:NO];  

    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

当您从 viewController2 导航到另一个视图时,执行 pushViewController 而不是像 presentView 这样的其他视图

[self.navigationController pushViewController:anotherViewController animated:YES];
于 2012-09-12T09:38:56.003 回答
0

试试这个方法可能对你有帮助

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


    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // [NSThread sleepForTimeInterval:0.1]; // simulate waiting for server response

    // Override point for customization after application launch.

    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

    // Initialise the navigation controller with the first view controller as its root view controller

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];

    // This is where we hide the navigation bar! :)

    [navigationController setNavigationBarHidden:NO];

    // Navigation controller has copy of view controller, so release our copy



    //[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];


    [self.viewController release];
    // Add the navigation controller as a subview of our window

    [_window addSubview:[navigationController view]];
    [_window makeKeyAndVisible];
    return YES;

}
于 2012-09-12T09:40:31.470 回答
0

将此代码放在委托类中。

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

    // Set the navigation controller as the window's root view controller and display.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}
于 2012-09-12T11:12:37.480 回答
0

如果您想在所有视图中启用导航,那么您必须在 AppDelegate.m 中声明导航,其中它将在所有视图中可见。我现在没有我的 mac rite,但这是我现在能提供的最好的建议 :)

于 2012-09-12T09:31:54.810 回答
0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.window.rootViewController =navigationController;
[self.window addSubview:[navigationController view]];
[self.window makeKeyAndVisible];
return YES;
}

将 uiviewcontroller 更改为 SecondViewController

于 2012-09-12T09:33:02.453 回答