简体   繁体   中英

How to navigate from app delegate class in window based iPhone application. How to write pushViewcontroller method in app delegate class

  • In my window base application I need to navigate to informationview from my appdelegate when i click on alert view button.
  • alert view works with NSlog.
  • But i need to push to the other view for this purpose i used

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

but it doesn't pushes. just nslog only prints

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    //To count the number of launches
    NSInteger i = [[NSUserDefaults standardUserDefaults] integerForKey:@"numOfCalls"];
    [[NSUserDefaults standardUserDefaults] setInteger:i+1 forKey:@"numOfCalls"];
    NSLog(@"the number of active calls are %d",i%3);
    if(i%3==0 && i!=0)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"you might prefer MedChart+"  message:@"Get it now for more options" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
        [alert show];
        [alert release];
    }

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

        if (buttonIndex == 0)
        {
             NSLog(@"canceled");

        }
        else if (buttonIndex == 1)
        {
            NSLog(@"Pushed to the information view ");

            InformationViewCotroller *info =  [[InformationViewCotroller alloc]initWithNibName:@"InformationViewCotroller" bundle:nil];
            [self.navigationController pushViewController:info animated:YES];     

        }

}

(dont consider 'i' values it is part of my logic). Thanks in advance

Before Navigate to any viewController , set the RootController for your navigationController of appDelegate. Add navigationController.View as subview of window.Then your root controller will be the first ViewController.from there you can push to any viewController.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM