pushViewController无法在AppDelegate中运行

时间:2013-05-30 08:53:57

标签: iphone ios

我想通过警报视图从AppDelegate推送到视图控制器。但它不起作用。只有警报视图才会解散。问题出在哪儿?在此先感谢您的帮助。 (N.B>我的初始视图在故事板中,但我正在推动视图控制器笔尖)

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

loginReapeat = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(repeatLoginProcess) userInfo:nil repeats:YES];

//First Launch Settings
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"])
{

}
else
{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstLaunch"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    [self alertShow];
}

[window addSubview:[navigationController view]];

[window makeKeyAndVisible];

return YES;
} 

-(void)alertShow{

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Help!" message:@"Need some help to use this App? Please tap the 'Help' button." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Help",nil];
[alert show];
}

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

NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Help"])
{
    SignUp *signUp = [[SignUp alloc]initWithNibName:@"SignUp" bundle:nil];

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

}
} 

4 个答案:

答案 0 :(得分:1)

试试这个:

SignUp *signUp = [[SignUp alloc]initWithNibName:@"SignUp" bundle:nil];                
self.navigationController = [[UINavigationController alloc] initWithRootViewController:signUp];
self.window.rootViewController = self.navigationController;

答案 1 :(得分:0)

您无法从App Delegate中进行推送,而是可以根据用户从UIViewController的选择决定将哪个UIAlertView显示为rootviewcontroller。

self.window.rootViewController = self.navController;

答案 2 :(得分:0)

    SignUp *signUp = [[SignUp alloc]initWithNibName:@"SignUp" bundle:nil];                
   UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:signUp ] autorelease];
    self.window.rootViewController = masterNavigationController;

答案 3 :(得分:0)

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

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

ViewControllerName *home=[[ViewControllerName alloc] initWithNibName:@"ViewControllerName" bundle:nil];
 self.window.rootViewController=home;

navcontroller=[[UINavigationController alloc]initWithRootViewController:home];
self.window.rootViewController = self.navController.view;
[self.window makeKeyAndVisible];
return YES;

}