Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Push segue from UIButton

Hi, I would like to add a verticle push segue to a UIButton. I have tried using the push option but I have now found out that it can only be used in table view controllers. How would I do this from a button?

//This will target the method 'buttonPressed'. [self myButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

//This will change views using the segue identified as 'secondView'.
- (void) infoButtonPressed{
[self performSegueWithIdentifier:@"secondView" sender:self];
}

Will this add a vertical push animation to the segue?

Ah, nah. This wouldn't. I'm sure it's just a extra method added on though.

How would I do that?

1 Answer

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

You can use the push segue as long as you have a navigation controller. If you don't then make sure your view controller is embedded in a navigation controller. In your storyboard select your view controller from the menu select Editor -> Embed in -> Navigation Controller.

Brillian! Thanks. Am I able to change this to a vertical push?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

You can achieve a vertical transition by adding a modal segue. Or write your own custom segue and animation.

Is this the same animation code for when the keyboard appears.

I have added the navigation controller and it works. However, am I able to hide the navigation bar but keep the back button visible?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

When you create a modal view controller then there is no navigation bar. You can add a button to dismiss the view controller.