按钮触发另一个VC,导航控制器后退按钮未显示在模拟器中

时间:2018-02-15 05:48:36

标签: ios objective-c uinavigationcontroller storyboard segue

我有3个VC。 1.根VC,注册VC和登录VC。

首先,我创建了按钮并通过Show(例如Push)将它们链接到所需的VC。然后,在Root VC中,我点击了Embeded in Navigation Controller。所有后退按钮显示在正确的VC上,如下图所示。

但是当我运行模拟器时,后退按钮都丢失了。

我已尝试命名所有segues,但它无效。

我不确定我哪里做错了,请帮忙

Story Board

Simulator 1

Simulator 2

Full storyboard

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

1 个答案:

答案 0 :(得分:0)

修改

根据评论中的讨论,解决方案如下所示:

创建UINavigationController的子类,说RootNavigationController

class RootNavigationController: UINavigationController {
    ....
}

enter image description here

现在,如果用户未注册,请通过在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。

原始答案

根据您的问题和屏幕截图,您的导航控制器似乎不是您的根视图控制器。

  1. 您可以将故事板中的NavigationController设置为初始视图控制器,如下所示:
  2. enter image description here

    1. 如果您已从代码设置RootViewController,则可以从AppDelegate设置此代码:

      let storyboard = UIStoryboard(name: "Main", bundle: nil)
      let initialViewController = storyboard.instantiateViewController(withIdentifier: "FirstNavigationController")
      
      self.window?.rootViewController = initialViewController
      self.window?.makeKeyAndVisible()