Reputation: 89
I have an application in storyboard and make the connections to second view controller
by push operation in the storyboard itself(without using coding).
Is there any way to pop to first view controller
without writing any code and using the storyboard?
Note:by using navigation controller
we will have back
button but if a button is created in the second view controller and when we tap on that button we should pop to first view controller.
Upvotes: 0
Views: 279
Reputation: 367
A solution that involves writing code once but can be used afterwards in your storyboards as a segue without further implementations would be some kind of PopSegue as subclass of a UIStoryboardSegue.
@interface PopSegue : UIStoryboardSegue
Overwrite the -perform method as follows.
@implementation PopSegue
- (void)perform
{
[[self.sourceViewController navigationController] popViewControllerAnimated:YES];
}
@end
Use a custom segue for back-navigation and specify the PopSegue class.
Upvotes: 0
Reputation: 3603
You can use an UnwindSegue
as well since iOS6, although it does require some code)* for push segues. For a good explanation of UnwindSegues
, see SO post, scroll down to "In a Nutshell"
)*Specifically, you need an unwind action, e.g.
- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue
Upvotes: 0
Reputation: 51
Storyboards don't provide a way to return from a segue without coding, but this can be easily accomplished with this code:
[self.navigationController popToRootViewControllerAnimated:YES];
Upvotes: 1
Reputation: 18470
Storyboards doesn't provide a "no-code" way to popViewController, you need to implement by yourself.
And if you want to pop to the first viewController you need to use:
[self.navigationController popToRootViewControllerAnimated:YES];
Upvotes: 0