简体   繁体   English

从AppDelegate无法使用pushViewController

[英]pushViewController is not working from AppDelegate

I want to push to a view controller from AppDelegate through an alert view. 我想通过警报视图从AppDelegate推送到视图控制器。 But its not working. 但是它不起作用。 Only the alert view dismisses. 仅警报视图关闭。 Where is the problem? 问题出在哪儿? Thanks in advance for the help. 先谢谢您的帮助。 (NB > my initial view is in the storyboard but i am pushing into a view controller nib) (注:我的初始视图在情节提要中,但我正在推入视图控制器笔尖)

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

}
} 

Try this: 尝试这个:

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

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

self.window.rootViewController = self.navController;
    SignUp *signUp = [[SignUp alloc]initWithNibName:@"SignUp" bundle:nil];                
   UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:signUp ] autorelease];
    self.window.rootViewController = masterNavigationController;
- (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;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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