Reputation: 179
I am actually trying to perform segue if the user is logged in to the home page and the segues are connected and I have given identifier as "loggedin"
and I have not currently coded for logout so there is no way of clearing NSUserDefaults
and I have checked that too it gives my value back!!
Below is my view did load method of first view controller in this I am getting mobile number from user for otp
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
self.custid =[defaults objectForKey:@"uid"];
NSLog(@"Customer id--%@",self.custid);
if(self.custid!=nil)
{
[self performSegueWithIdentifier:@"loggedin" sender:self];
}
[_checkboxb setBackgroundImage:[UIImage imageNamed:@"unsigned checkbox"]
forState:UIControlStateNormal];
[_checkboxb setBackgroundImage:[UIImage imageNamed:@"signed check box"]
forState:UIControlStateSelected];
UIGraphicsBeginImageContext(self.view.frame.size);
}
this is my storyboard and in log u can see the error
and my code of that view controller is executing not the first view the logged in is executing but the view is of first view controller
Upvotes: 0
Views: 126
Reputation: 15778
Don't check user login status in first view controller. Check login status in AppDelegate
and assign root view controller according to that.
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIViewController *viewController;
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if([defaults objectForKey:@"uid"]!=nil)
{
viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];
}
else
{
viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController1"];
}
self.window.rootViewController = viewController;//With out NavigationController
//self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:viewController];//With NavigationController
[self.window makeKeyAndVisible];
return YES;
}
Upvotes: 1