0
我有一個應用程序。在我這樣做時,應用程序是第一次啓動我添加LoginViewController其他明智它將添加splitViewController它工作正常,但問題是,我想當loginViewController被添加,當我按登錄屏幕上的singButton然後它應該添加splitViewController窗口代碼確實是這樣,但是當我按下登錄唱歌但隨後應用程序關閉,當我再次打開它,然後它顯示我splitViewController添加視圖在第一次啓動在iPad應用程序的主窗口
這裏是我的代碼
[[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];
}
[email protected]"Jamshaid";
[email protected]"NO";
[email protected]"Logout";
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
我給你我的全部代碼plase看到我的更新代碼 – user2240329
@ user2240329 - 檢查我的另一個答案:) – iPatel