Najeebullah Shah
Najeebullah Shah

Reputation: 3709

second view call from first view

I want to call secondview from my current view but this code suggested by someone is not working properly

UINavigationController *nav=[[UINavigationController alloc] initWithNibName:@"Second" bundle:[NSBundle mainBundle]];
[nav pushViewController:@"Second" animated:YES];

Upvotes: 1

Views: 148

Answers (3)

Kjuly
Kjuly

Reputation: 35171

  1. I suggest you put naviagtionbar initialization in your application:didFinishLaunchingWithOptions: if it's your rootViewController. You can initiate it with rootViewController, like so:

    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:firstViewController_1];
    self.window.rootViewController = nav;
    [nav release];
    
  2. Push other views in your view controller(e.g. your FirstViewController.m):

    SecondViewController * secondViewController_2 = [[[NSBundle mainBundle] loadNibNamed:@"SecondViewController" owner:self options:nil] lastObject];
    // Or: SecondViewController * secondViewController_2 = [[SecondViewController alloc] init...] autorelease];
    [self.navigationController pushViewController:secondViewController_2 animated:YES];
    

Upvotes: 1

msgambel
msgambel

Reputation: 7340

Why are you pushing an NSString onto a UINavigationController? I think what you want is:

SecondView * vc = [[SecondView alloc] initWithNibNamed:@"SecondView"];
[self.navigationController pushViewController:vc animated:YES];
[vc release];

Hope that Helps!

Upvotes: 2

Rishabh
Rishabh

Reputation: 62

You can use the presentModalViewController for the second view.

hope this will help you.

[self.navigationController presentModalViewController:SecondView animated:YES];

Upvotes: 1

Related Questions