我正在开发一款应用,我遇到了UINavigationcontroller
的问题。
首先在app委托中我检查用户是否已登录,如果是,我将他带到主屏幕,如果不是我将他带到登录界面。
这是我的代码:
UINavigationController *diabetesNavigationController = [UINavigationController alloc];
LoginViewController *loginPage = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
MainViewController *mainPage = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
if ([DataStore instance].userIsLoggedIn)
diabetesNavigationController = [diabetesNavigationController initWithRootViewController:mainPage];
else
diabetesNavigationController = [diabetesNavigationController initWithRootViewController:loginPage];
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[[UINavigationBar appearance]setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance]setTitleTextAttributes:navbarTitleTextAttributes];
[self.window setRootViewController:diabetesNavigationController];
用户退出时的问题是,他返回登录屏幕,但没有navigationcontroller
。
我在MainViewController中做了一些东西,就是这样:
-(void)viewDidAppear:(BOOL)animated
{
self.navigationItem.title = @"Diabetes";
UIBarButtonItem *settingButton=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"burger.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(onBurger:)];
self.navigationItem.rightBarButtonItem = settingButton;
self.navigationItem.leftBarButtonItem.enabled = YES;
}
因此,当我使用以下代码注销用户时:
LoginViewController *loginPage = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
[self.navigationController setViewControllers:[NSArray arrayWithObjects:loginPage, nil] animated:YES];
我进入登录界面,但没有Navigationcontroller
。我试图在所有视图委托中将Hidden属性设置为NO,但它仍然存在此问题。
答案 0 :(得分:0)
你可以试试这个:
UIWindow *window = [UIApplication sharedApplication].keyWindow;
LoginViewController * loginPage = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: loginPage];
[window.rootViewController presentViewController:nav animated:YES completion:NULL];
让我知道它是否有效.. :)