所以在我的App.Delegate中,我正在这样做 -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController: self.loginViewController];
self.window.rootViewController = navigation;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
在我的登录控制器中我正在这样做 -
- (IBAction)login:(UIButton *)sender {
NSString *username = self.userName.text;
NSString *password = self.password.text;
[AccountUtils emailLogin:username password:password useCookie:true callback:^(NSDictionary *loginResponseJSON){
if([loginResponseJSON count] != 0){
[self performSelectorOnMainThread:@selector(displaySearchController) withObject:nil waitUntilDone:YES];
// [self performSelectorOnMainThread:@selector(switchState) withObject:nil waitUntilDone:YES];
} else {
//incorrect entry info view here.
}
}];
}
- (void) displaySearchController {
SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchView" bundle:[NSBundle mainBundle]];
UINavigationController *navigator = self.navigationController;
[navigator popViewControllerAnimated: YES];
[navigator pushViewController: searchViewController animated:YES];
}
如果我正确登录,我会转到第二个控制器的视图,但在顶部我仍然可以“返回”登录页面。我不希望这种情况发生,我认为这种情况会被popViewControllerAnimated行所关注。我怎么做到这一点,当我登录时,我不允许回到登录页面?(换句话说,我想从导航控制器的堆栈弹出登录控制器?)
答案 0 :(得分:3)
如果您只想删除loginVC,可以在用户登录后将新的navigationController设置为AppDelegate的rootViewController。这样您就可以移动displaySearchController
中的AppDelegate
方法并调用用户登录后的此方法(来自loginVC):
-(void)displaySearchController{
SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchView" bundle:[NSBundle mainBundle]];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController: searchViewController];
self.window.rootViewController=navigation;
}
否则,如果您真的想要推送动画,可以从SearchDispalyController的viewDidAppear
中的navigationController viewControllers堆栈中删除loginVC:
-(void)viewDidAppear:(BOOL)animated{
NSMutableArray *stackVCs=[self.navigationController.viewControllers mutableCopy];
int idx=[stackVCs indexOfObject:self];
//this remove the previous viewcontroller from the stack
[stackVCs removeObjectAtIndex:idx-1];
self.navigationController.viewControllers=stackVCs;
[super viewDidAppear:animated];
}
在推送searchVC之前的loginVC中你应该调用它来隐藏后退按钮:
[navigation.navigationItem setHidesBackButton:YES];
答案 1 :(得分:0)
您不希望将UINavigationController与LoginViewController一起使用,并且您不想推送SearchViewController。相反,使用带有SearchViewController的UINavigationController,当你显示它时,将它设为rootViewController。
答案 2 :(得分:0)
这样做是为了实现你想要的目标。
displaySearchController
方法移至AppDelegate.m
文件displaySearchController
文件AppDelegate.h
方法
现在将displaySearchController
文件中的AppDelegate.m
方法定义为:
- (void) displaySearchController {
SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchView" bundle:[NSBundle mainBundle]];
UINavigationController *navigator = [[UINavigationController alloc]initWithRootViewController:searchViewController];
self.window.rootViewController = navigator;
}
从您的showNewViewController
调用新的本地方法loginController
:
[self performSelectorOnMainThread:@selector(showNewViewController) withObject:nil waitUntilDone:YES];
现在将showNewViewController
文件中的loginController.m
定义为
-(void)showNewViewController {
AppDelegate *appDele = [UIApplication sharedApplication].delegate;
[appDele displaySearchController];
}
不要忘记将AppDelegate.h
文件导入loginController.m
这肯定对你有帮助。