我有一个应用程序。我正在这样做,当应用程序首次启动时,我正在添加 LoginViewController 否则它将添加 splitViewController 它工作正常,但问题是我希望在添加 loginViewController 并且当我在 loginscreen 上按下 singButton 时,它应该将 splitViewController 添加到窗口代码确实是这样,但是当我按下登录 singin 但应用程序关闭时,当我再次打开它时,它显示我 splitViewController
这是我的代码
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(actionNotificationData:)
name:@"reloadSplit"
object:nil];
[self.window addSubview:[loginViewController view]];
)
else{
[self.window addSubview:[splitViewController view]];
}
-(void)actionNotificationData:(NSNotification *)notification {
[self.splitViewController removeFromParentViewController];
window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:splitViewController];
[window makeKeyAndVisible];
}
这是signInButtonAction
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadSplit" object:self];
[self dismissModalViewControllerAnimated:YES];
我的代码
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
self.loginViewController=[[[LoginViewController alloc]init] autorelease];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
if ([detailNav.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
UIImage *image = [UIImage imageNamed:@"Nav.png"];
[detailNav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
user_Name=@"Jamshaid";
isClickedLogin=@"NO";
userLogin=@"Logout";
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;