Cannot programmatically perform segue - ios

I have a storyboard segue with an identifier that is 'Push to ResumeView'.
I try calling it in the ViewController that I'm in at the point, by doing
[self performSegueWithIdentifier: #"Push to ResumeView" sender: self];.
But nothing happens?
I'd much rather just push the ViewController using the top NavigationController or something, but I can't see how to do that either.

Try implementing the shouldPerformSegueWithIdentifier:sender: or prepareForSegue:sender: methods in the 'from' view controller. Put a break point or NSLog() inside the method to inspect the segue identifier. This will prove that you indeed set up the segue correctly in the storyboard.
If you want to manually push your next view controller to the top of the navigation controller, use pushViewController:animated:. However, if you are using storyboard, the preferred way is to use segues.

Try this one.
UIViewController *yourResumeView=[self.storyboard instantiateViewControllerWithIdentifier:#"PushToResumeView"];
[self.navigationController pushViewController:yourResumeView animated:YES];

Related

Segue from screen with several buttons?

I am trying to write an app using UINavigationViewController. My first screen has several buttons on it, and on the click of each button, I want to segue to a UIViewController. I know that I can add a segue on each button, all pointed to the UIViewController that I want to go to, but I was wondering if it is possible to use only one segue that can be fired from each of the buttons.
If that is not possible, I was wondering if it was possible to open the second UIViewController from the first one, on button click, and provide a Back button like the UINavigationView provides. I did manage to get everything on this idea working, except for the back button. I mean I can put a standard button somewhere on the screen and go back, but I'd like the standard back button on the UINavigationView.
Phew! I'm not sure if that makes any sense.
I know that I could also use a tableview, but I'm trying to set this up with buttons.
Thanks
Edit: Thank you to everyone that answered. I now have this working. I would vote up the answers, but I don't have enough posts to do it. I appreciate the answers!
If you need to have separate action functions for each button, suggest that you segue from the main controller to the other controller and create a segue identifier (see xcode procedure below); then, use performSegueWithIdentifier from each of the button action functions. You can also take advantage of the prepareForSegue. To create the segue, control-drag from the left button in the controller in the storyboard to the controller you want to segue to and pick show.
Check the example code in swift that I did for a very similar problem in the SO reference
Linking View Controllers through button
You can embed the main controller in a navigation controller and that will give you the ability to navigate back. If you have multiple layers you can also use unwind segue.
Link each button to one single action (ex. buttonClick) in that ViewController and then perform the appropriate segue using pushViewController method on self.navigationController
-(IBAction)buttonClick:(id)sender {
if(sender.id == self.button1) {
DestinationViewController *vc = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"VC_IDENTIFIER"];
[self.navigationController pushViewController:vc animated:YES];
}
Or if you already have that 1 segue defined in storyboards you can use
[self performSegueWithIdentifier:#"SegueIdentifier" sender:self];
And use that inside the buttonClick method. Using the 1st example, or the second one as long as the segue you setup in the storyboards is a push then you should already get the back button as that is the default behavior for pushing view controllers onto the navigation stack.

How to perform custom segue across two storyboards?

so I inherited an old project at work that's broken up into a ton of different storyboards. While this hasn't really been too much of a hassle, the client now wants a custom segue animation that goes from a View Controller on Storyboard A to a View Controller on Storyboard B and I can't figure it out for the life of me.
I have the animation worked out if the views are on the same Storyboard, but I can't get it hooked up to a transition to another storyboard.
You can't do this without using a trick, because you can't connect a segue between storyboards. You can instantiate the controller manually in the other storyboard, then do whatever custom animation you want to present or push it in code. Since the main reason for using a segue (as opposed to transitioning to the new controller in code) is that you can see the connections between your controllers in the storyboard, there's not much reason to use a segue in your case.
If you really insist on using a segue, then you need to put a "dummy" controller in your first storyboard that you connect a custom segue to. The code in that segue switches out the dummy controller for the real controller you want to segue to in the other storyboard. You can find a reference to that technique here, http://spin.atomicobject.com/2014/03/06/multiple-ios-storyboards/.
Find below code for accessing another storyboard view:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"storyboard_A_view_identifier"]) {
UIStoryboard *storyBoardB = [UIStoryboard storyboardWithName:#"storyBoardB" bundle:nil];
UIViewController *anotherViewController = [storyBoardB instantiateViewControllerWithIdentifier:#"storyboard_B_view_identifier"];
// use anotherViewController and perform custom animation on it
}
}

Unable to programmatically "push" viewcontroller using showSegue in IOS8

I have defined a segue from source tableview controller to another and trying to programmatically transition to the destination controller upon click of a UITableViewCell using the following statement:
[self performSegueWithIdentifier:#"pushToDestinationViewController" sender:self];
However, I find that the segue doesn't result in a "push" to the destination view controller.
On the other hand, if I wire the segue to a specific cell in the source view controller it works.
In addition, if I call the destination viewcontroller programmatically using:
[self showViewController:DestinationViewController] it works.
Can someone advise if this is a known issue in iOS 8 or if I am missing something here.
Did you have a segue in your Storyboard called pushToDestinationViewController? You will need to make sure that you have this segue in your Storyboard first like below.
Or, if you just want to simply push another view controller, you can just use [self.navigationController pushViewController:destinationViewController].

ECSlidingViewController with Push and Unwind Segue

I am using ECSlidingViewController with storyboards. ECSlidingVC is my root (starting) controller. My left menu is a TableView with static cells, and my TopViewController is a navigation controller. I want to have a single NavigationController for all my app.
From my left menu i cant use push or unwind segues, i understand that part though. i can only use ECSlidingSegue which changes topviewController of ECSlidingVC and which destroys my navigation controller and it's stack.
i want to be able to go back from a menu item VC to previous VC in my main nav controller. lets say basically i want ECSlidingVC to not change topViewController but push destination viewController to my source.topViewController.navigationController.
Also i need to use unwind segues with my menu items. i need to go back to a VC in my main nav controller.
i inspected ECSlidingSegue source code and all it does is to replace topViewController.
is there a built in method (or segue) in ECSlidingViewController for pushing (or unwinding) VC into source.topViewController.navController or do i need to implement a custom segue myself?
I think the best way to go is for you to implement a custom segue yourself. Something like ECSlidingNavigationSegue, which would look for your topViewController, then check whether it's a UINavigationController and then push the destinationController to it.
It's basically the same perform method as the ECSlidingSegue, but with this feature of pushing a controller to the topViewController instead of replacing it.
Good luck!
In case someone haven't found answer, I did it in this way.
1- #import "UIViewController+ECSlidingViewController.h" to your menuViewController
2- Set stroboardID of your destinationViewController to "someID"
3- When triggering some action, in backend, use this code:
if(self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionCentered){
[self.slidingViewController anchorTopViewToRightAnimated:YES];
}
else{
self.slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"someID"];
[self.slidingViewController resetTopViewAnimated:YES];
}

is there any way to popView controller in Storyboard?

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.
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];
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];
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
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.

Resources