Search code examples
iosuinavigationbaruibarbuttonitempushviewcontroller

Push to different views with one BarButton


I have my main window with a Navigation Bar and one BarButton in the top right corner. I have a saved value, and depending on if it is TRUE or FALSE, I want to push to a different controller. Now pushing to one is just Ctrl+Drag in IB, but what about if I want to choose beween views to push? Any suggestions?


Solution

  • Just implement a simple IBAction that you connect with your ~UIBarButton

    -(IBAction)barButtonPressed {
         if (yourBoolean) {
              TrueViewController *trueViewController = [[TrueViewController alloc] init];
              [self.navigationController pushViewController:trueViewController animated:YES];
         } else {
              FalseViewController *falseViewController = [[FalseViewController alloc] init];
              [self.navigationController pushViewController:falseViewController animated:YES];
         }