0

My app has a sign in button and a sign up button, which are UINavigationButtons and UIButtons respectively. Either segues to a new screen that, on success, should PopToRootViewController; However, when I successfully sign in, my sign in and sign up buttons are still present. I have a method that decides whether or not to display the buttons that gets called in the viewDidLoad method. Thus, when I stop/run the app again, the buttons disappear as they should. Can anyone give me advise on how to get these buttons to hide? Thank you.

Bonus points: I also have a log out button that has a similar issue; I have to re-run the app before my view controller realizes it should hide the logout button and show the sign in/up buttons.

Vineet Singh
  • 4,009
  • 1
  • 28
  • 39
user1034868
  • 65
  • 11

1 Answers1

1

The problem is that viewDidLoad is only called once, so it is hardly suitable for this purpose; it has to do with the view coming into existence, and nothing to do with the interface. Use viewWillAppear: and make the decision about whether to show or hide the buttons on the basis of, say some info you've stored in NSUserDefaults (like, has the user signed in or not).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I have: `if(self.signedIn) { [self.homeView hideSignInButton]; [self showRightBarButton:self.logout]; [self hideLeftBarButton:self.signin]; } if(!self.signedIn) { [self hideRightBarButton:self.logout]; [self showLeftBarButton:self.signin]; }` When I move it to my viewWillAppear from my viewDidLoad, it crashes with `*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'` – user1034868 May 07 '13 at 03:00
  • Update: So, this error seems to be caused only by my "show" button code, not my "hide" button code, and only for the UINavButtons. This code is as follows: `- (void) showRightBarButton:(UIBarButtonItem *)button { NSMutableArray *toolbarButtons = [self.navBar.rightBarButtonItems mutableCopy]; if (![toolbarButtons containsObject:button]) { [toolbarButtons addObject:button]; [self.navBar setRightBarButtonItems:toolbarButtons animated:NO]; } }` – user1034868 May 07 '13 at 03:28