Question

I am new to iPhone developer,

I have 4 page in my Application, my Application is viewBasedApplication.

I made my 1st page(LicAppViewController) as RootViewController, here is my code.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    self.viewController = [[[LicAppViewController alloc] initWithNibName:@"LicAppViewController" bundle:nil] autorelease]; 

    UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];
    return YES; 
}

on button click i am navigation to 2nd page(PlanPage)

-(void)btnClicked{

    PlanPage *viewController = [[PlanPage alloc]initWithNibName:@"PlanPage" bundle:nil];
    [UIView beginAnimations:@"Flip" context:nil]; 
    [UIView setAnimationDuration:0.7]; 
    [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
    [self.navigationController pushViewController:viewController animated:YES];
    [UIView commitAnimations];
    [viewController release];

}

till now it is working fine, but when i select a row in 2nd page it crashes my application, i want to navigate to 3rd page(DetailPlanPage), here is my code

    DetailPlanPage *nextController = [[DetailPlanPage alloc] initWithNibName:@"DetailPlanPage" bundle:nil];
    [self.navigationController presentModalViewController:nextController animated:TRUE];

but when i write, this line:

      [self.navigationController pushViewController:nextController animated:YES];

instead of:

       [self.navigationController presentModalViewController:nextController animated:TRUE];

it's working fine. (I am not sure but crash of my application may be because of viewBased Application)

Thanks In Advance !

Was it helpful?

Solution

set rootview controller first

remove that code

[self.window addSubview:navigationController.view];

and include

self.window.rootViewController = navigationController;

in present modal view controller u can try like this

    yourview *detailViewController = [[yourview alloc] initWithNibName:@"yourview" bundle:nil];
         UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(dismiss)];
     detailViewController.navigationItem.leftBarButtonItem = doneButton;
        UINavigationController *nav;
        nav=[[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
        [self presentModalViewController:nav animated:YES];
        [detailViewController release];
[doneButton release];

-(void) dismiss
{
      [self dismissModalViewControllerAnimated:YES];
  }

OTHER TIPS

Try

[self presentModalViewController:nextController animated:YES];

you would also want to set the delegate for nextController to self and add a delegate function to dismiss Modal View Controller.

The most important difference is about semantics. Modal view controllers typically indicate that the user has to provide some information or do something. This link explains it more in depth:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

When you present a modal view controller, the system creates a parent-child relationship between the view controller that did the presenting and the view controller that was presented. Specifically, the view controller that did the presenting updates its modalViewController property to point to its presented (child) view controller. Similarly, the presented view controller updates its parentViewController property to point back to the view controller that presented it. And also another link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top