Advertisement
Guest User

UINavigationBar out of sync issue

a guest
Mar 14th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // main.m
  2.  
  3. #import <UIKit/UIKit.h>
  4.  
  5. int main(int argc, char * argv[]) {
  6.     @autoreleasepool {
  7.         return UIApplicationMain(argc, argv, nil, @"AppDelegate");
  8.     }
  9. }
  10.  
  11.  
  12. // AppDelegate.m
  13.  
  14.  
  15. #import <UIKit/UIKit.h>
  16.  
  17. @interface AppDelegate : UIResponder <UIApplicationDelegate>
  18. @property (strong, nonatomic) UIWindow *window;
  19. @end
  20.  
  21. @interface A : UIViewController
  22. @end
  23.  
  24. @interface B : UIViewController
  25. @end
  26.  
  27. @implementation A
  28.  
  29. - (void)viewDidLoad {
  30.     [super viewDidLoad];
  31.  
  32.     self.navigationItem.title = @"RED";
  33.     self.view.backgroundColor = [UIColor redColor];
  34. }
  35.  
  36. - (void)viewWillAppear:(BOOL)animated {
  37.     [super viewWillAppear:animated];
  38.  
  39.     B *b = [[B alloc] init];
  40.     [self.navigationController setViewControllers:@[b]];
  41. }
  42.  
  43. @end
  44.  
  45. @implementation B
  46.  
  47. - (void)viewDidLoad {
  48.     [super viewDidLoad];
  49.  
  50.     self.navigationItem.title = @"GREEN";
  51.     self.view.backgroundColor = [UIColor greenColor];
  52. }
  53.  
  54. @end
  55.  
  56. @implementation AppDelegate
  57.  
  58. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  59.     UINavigationController *nc = [[UINavigationController alloc] init];
  60.     UIViewController *a = [[A alloc] init];
  61.  
  62.     [nc setViewControllers:@[a]];
  63.    
  64.     UIWindow *window = [[UIWindow alloc] init];
  65.     window.backgroundColor = [UIColor whiteColor];
  66.     window.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  67.     window.rootViewController = nc;
  68.     [window makeKeyAndVisible];
  69.  
  70.     self.window = window;
  71.    
  72.     return YES;
  73. }
  74.  
  75. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement