2
votes

I have one original view controller with four destination view controllers. I want to be able to push segue with a navigation controller to ALL of the destination view controllers from the original. I have tried...

- (IBAction)notificationsButtonPushed:(id)sender {

    NotificationsViewController *notifications = [[NotificationsViewController alloc]init];

    [self.navigationController pushViewController:notifications animated:YES];

}

- (IBAction)messagesButtonPushed:(id)sender {

    MessagesViewController *messages = [[MessagesViewController alloc] init];

    [self.navigationController pushViewController:messages animated:YES];

}

- (IBAction)settingsButtonPushed:(id)sender {

      if (canMessage) {

          SettingsViewController *settings = [[SettingsViewController alloc]init];

          [self.navigationController pushViewController:settings animated:YES];
      }

      else {

          NSLog(@"Can't Message");
      }

}

- (IBAction)previewButtonPushed:(id)sender {

    PreviewViewController *preview = [[PreviewViewController alloc]init];

    [self.navigationController pushViewController:preview animated:YES];

}

and this just gives me an empty view controller without my UI components.

Note: I also have tired "initWithNidName:" and passed in the storyboardID of each destination view controller and it gives me Error:

'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/B7E025E5-D7D2-4FFD-B49C-E10DF5E94C44/LifePoints.app> (loaded)' with name 'preview' 

I also have tried... (with storyboard segues set to "Push")

    - (IBAction)notificationsButtonPushed:(id)sender {

    [self performSegueWithIdentifier:@"notifications" sender:self];

}

- (IBAction)messagesButtonPushed:(id)sender {

    if (canMessage) {

        [self performSegueWithIdentifier:@"messages" sender:self];

    }

    else {
        NSLog(@"Can't Message");
    }
}

- (IBAction)settingsButtonPushed:(id)sender {

    [self performSegueWithIdentifier:@"settings" sender:self];

}

- (IBAction)previewButtonPushed:(id)sender {

    [self performSegueWithIdentifier:@"preview" sender:self];

}

Although this does push the destination view controllers onto the screen with the appropriate segue type, it does not segue to the correct destination view controller. It only seems to segue to the last attached storyboard segue.

Does anyone know how to correctly apply this and have it behave in the form I am looking for?

EDIT

It is important to note I am checking to see if a condition is met the "messagesButtonPushed" method. I am checking to see if user is allowed to message, and if they are, then segue to the VC.

1

1 Answers

1
votes

You don't need any code to implement the basic segues.

In your story board ensure that your original view controller is embedded in a navigation controller (Select the original View and select Edit->Embed in->Navigation Controller).

Then you can simply control drag from each of your four buttons to the corresponding destination views, selecting "push" as the segue type. You can then click on the segue icon between the two views to give each segue an identifier.

You can delete your IBAction methods and any actions on the buttons that link to them.

I suggest you complete a Storyboard Tutorial to learn how storyboards and segues work.

If you do want to perform a segue programatically then you can control drag from the yellow view controller icon at the bottom of the view to the destination. You can then invoke the segue with performSegueWithIdentifier as per your second code - In your case your could have two different segues and trigger the store segue or the other one depending on purchase status