2

I just started to use Storyboard in Xcode. I have a starting view that has some buttons inside. Is there a way to load a special view when a button is clicked?

I only found this workaround:

-(IBAction)loadRegistration:(id)sender { // load registration controller UIStoryboard *storyboard = self.storyboard; RegisterController *svc = [storyboard instantiateViewControllerWithIdentifier:@"RegisterController"]; [self presentViewController:svc animated:YES completion:nil]; } 
0

2 Answers 2

5

You don't need any code to load a new view. You just control-drag from the button to the controller you want to present, and choose the segue type. If the controller with the button is in a navigation controller you can choose push or modal, if it's not, then you want to choose modal.

Sign up to request clarification or add additional context in comments.

2 Comments

I always used "push", which never worked. However, "modal" works as expected. Thx.
@dooonot, yes, push only works if the controller is embedded in a navigation controller.
1

The way you did it seems ok. You can also connect the current View Controller to the one you want to present with a segue in the Interface Builder (ctrl + drag). When the button is tapped, you would call [self performSegueWithIdentifier:@"segue identifier"];. Of course, you set the id of the segue in the IB. Even more simpler would be to connect the button with the new View Controller in IB (also ctrl+drag). This way you won't even need the IBAction.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.