我有3个VC。 1.根VC,注册VC和登录VC。
首先,我创建了按钮并通过Show(例如Push)将它们链接到所需的VC。然后,在Root VC中,我点击了Embeded in Navigation Controller。所有后退按钮显示在正确的VC上,如下图所示。
但是当我运行模拟器时,后退按钮都丢失了。
我已尝试命名所有segues,但它无效。
我不确定我哪里做错了,请帮忙
News.m InitView控制器
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(![(AppDelegate*)[[UIApplication sharedApplication] delegate] authenticated]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
RootViewController *initView = (RootViewController*)[storyboard instantiateViewControllerWithIdentifier:@"initialView"];
[initView setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:initView animated:NO completion:nil];
} else{
// proceed with the profile view
}
}
RootViewController.m
#import "RootViewController.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
@interface RootViewController ()
@end
@implementation RootViewController
@synthesize loginView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnLogin:(id)sender {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loginActionFinished:)
name:@"loginActionFinished"
object:loginView];
}
#pragma mark - Dismissing Delegate Methods
-(void) loginActionFinished:(NSNotification*)notification {
AppDelegate *authObj = (AppDelegate*)[[UIApplication sharedApplication] delegate];
authObj.authenticated = YES;
[self dismissLoginAndShowProfile];
}
- (void)dismissLoginAndShowProfile {
[self dismissViewControllerAnimated:NO completion:^{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabView = [storyboard instantiateViewControllerWithIdentifier:@"profileView"];
[self presentViewController:tabView animated:YES completion:nil];
}];
}
@end
答案 0 :(得分:0)
根据评论中的讨论,解决方案如下所示:
创建UINavigationController
的子类,说RootNavigationController
。
class RootNavigationController: UINavigationController {
....
}
现在,如果用户未注册,请通过在RootNavigationController
中设置rootviewcontroller将其路由到AppDelegate
:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "RootNavigationControllerID")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
在屏幕截图中,RootViewController是您的Root VC。
根据您的问题和屏幕截图,您的导航控制器似乎不是您的根视图控制器。
NavigationController
设置为初始视图控制器,如下所示:如果您已从代码设置RootViewController
,则可以从AppDelegate
设置此代码:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "FirstNavigationController")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()