This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainViewController.m
59 lines (43 loc) · 1.89 KB
/
MainViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// MainViewController.m
// ComplexNavigation
//
#import "MainViewController.h"
#import "LoginViewController.h"
#import "AnotherScreenViewController.h"
@interface MainViewController()
@end
@implementation MainViewController
-(void)viewDidLoad {
[super viewDidLoad];
}
-(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([prefs objectForKey:@"LOG_IN_NEEDED"] == Nil) {
/////////////////////////
// opening the login screen this way works always OK
/////////////////////////
// show the log in screen if needed
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
LoginViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginScreen"];
[self.navigationController pushViewController:vc animated:NO];
}
else if ([prefs objectForKey:@"SHOW_ANOTHER_SCREEN"] == Nil) {
/////////////////////////
// opening another screen after we return from the login screen makes a mess
// The view controller thinks something was pushed, the back button is visible, but this (the `Main`) screen is
// visible instead of the `Another` screen. Tapping the back button pops the main screen and the app is black.
/////////////////////////
// show another screen if needed and set its flag, that is should not show in the future
[prefs setObject:@"1" forKey:@"SHOW_ANOTHER_SCREEN"];
[prefs synchronize];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
AnotherScreenViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"AnotherScreen"];
[self.navigationController pushViewController:vc animated:NO];
}
}
@end