【问题标题】:How to navigate from app delegate class in window based iPhone application. How to write pushViewcontroller method in app delegate class如何在基于窗口的 iPhone 应用程序中从应用程序委托类导航。如何在应用委托类中编写 pushViewcontroller 方法
【发布时间】:2012-03-12 17:23:17
【问题描述】:
  • 在我的窗口基础应用程序中,当我单击警报视图按钮时,我需要从我的 appdelegate 导航到信息视图。
  • 警报视图适用于 NSlog。
  • 但我需要为此目的推送到另一个视图

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

但它不会推动。只是 nslog 只打印

- (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];     

        }

}

(不要认为“i”值是我的逻辑的一部分)。 提前致谢

【问题讨论】:

  • 您是否验证过 self.navigationController 是一个有效的对象?
  • 是的,我已经在 appdelegate.h 中声明了
  • 您是否在调试器或日志中打印了它的值?

标签: iphone objective-c xcode uinavigationcontroller pushviewcontroller


【解决方案1】:

在导航到任何 viewController 之前,为 appDelegate 的 navigationController 设置 RootController。 添加navigationController.View作为窗口的子视图。然后你的根控制器将是第一个ViewController。从那里你可以推送到任何viewController。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多