Segue performs even though identifier is not met - ios

i've created a segue form a uibutton to a viewController with the style push. I only want this segue to be pushed if a criteria is met. Therefor i've created an identifier like this:
[self performSegueWithIdentifier:#"LoginSuccessful1" sender:self];
But it seems like that the segue is beeing pushed even though the performSegueWithIdentifier has not been called. How can i fix this?

Instead of having the segue go directly from the button, hook up the UIButton to an IBAction on your view controller. Then, in this IBAction, check your condition and call your performSegue. When hooking a segue directly from a button, the ViewController is not consulted first.

Remove the segue from button and connect it from ViewController to AnotherViewController as pushsegue not from UIButton
And check the condition and perform the segue
if(this == that){
[self performSegueWithIdentifier:#"LoginSuccessful1" sender:self];
}

Related

Cannot programmatically perform segue

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

Stopping a push segue from going until told to move forward - Obj C

I have an IBOutlet on a button that will be used as a login button. It gets sent to a function for that button and I want to do my processing in there and once completed push the viewcontroller forward.
I have the login button linked already to the view controller to move forward. How do I pause that push segue from moving forward until the application does its processing and than tells it to move forward?
Instead of linking the button directly to the next view controller, create a general segue from the one UIViewController to the next UIViewController and specify an identifier for that segue, so that within the .m of you view controller, you can use performSegueWithIdentifier: when you're ready to perform the segue.
To connect the view controllers in this way, click on the black bar below the first UIViewController and control + drag from the yellow button to the second UIViewController.
Then to perform the segue use:
[self performSegueWithIdentifier:#"TheViewControllerIdentifier" sender:self];
within your button's IBAction method if the condition is met.
Do not link directly the button on the storyboard to the next viewController, link it to an IBAction instead, where you put your login code and when login is done you push the next viewController like this
[self.navigationController pushViewController:theNewViewController];
If you donĀ“t know how to create the newViewController try:
MyViewController newViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"theIdentifier"]
And don't forget to add theIdentifier to the new viewController in the storyboard
You can use the following method in your controller
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
In this method you can do your custom processing and indicate if you want the segue to be performed or not

IOS7 - performSegueWIthIdentifier does not have any effect

I have a problem in iOS7 where I am calling a segue with performSegueWithIdentifier (I have code just like this that works just about everywhere else), then I log the segue in prepareForSegue, then I log again the view controller (VC) that the segue is supposed to push to the top.
prepareForSegue gets called appropriately and the segue has the correct string as its identifier property. Yet the VC that it is supposed to push to the top never gets initialized nor viewWillAppear gets called.
The segue I am talking about, which is the only one that does not work (all the other ones work in both ios6 and 7), is the one leading form the center VC to the right VC. By the way, this works flawlessly in iOS6.
What could be the cause?
the code:
-(IBAction)gotoMainMenu:(id)sender{
DLog(#"DifferentName");
[self performSegueWithIdentifier:#"DifferentName" sender:self];
}
Get in the habit of not wiring up segue's to buttons. Wire them up to the VC and then in the touchUpInside action, fire off the performSegueWithIdentifier.
I had the same issue and solved it as follows. In view A I had a segue that was triggered by a button (UIButton) and the button was also connected to an action in my controller. When I clicked the button in View A, View B would appear as expected. However, when I tried clicking a button in View B to go to View C nothing happened just as you described above.
In my case the issue was resolved in View A. I removed the segue that was tied to the button and let the IBAction that was associated with the button handle calling the performSegueWithIdentifier, then I created a new manual segue that was only tied to the view and voila things worked as expected again.
In short, I guess make sure you don't have both and action and a segue linked to the same button. Hope this helps.

Storyboard Segue to Multiple Views?

I am setting up a bunch of view controllers in my storyboard and have a 'Next' button.
I need this to segue to two different view however my storyboard won't allow it. For example if certain criteria are met the next button will go to one view, if not, it will go to the other view.
Any help much appreciate achieving this.
Thanks.
You need to create the two segues from your view controller, not from the button. In the storyboard, control-drag from the view controller to where you want the segue to go. Repeat for the other segue. Click on each segue and give them unique identifiers (for this demo I'll use "segue1" and "segue2").
Then, go to your ViewController that initiated the segues. You need to set an action up for your button.
-(void)buttonPressed:(UIButton*)sender{
if(criteria met){
[self performSegueWithIdentifier:#"segue1" sender:self];
}
else {
[self performSegueWithIdentifier:#"segue2" sender:self];
}
}
Sender is self in this case because it is the view controller causing the segue, not the button directly. You will also need to implement prepareForSegue.

Segue not calling prepareForSegue

Perhaps I am missing something simple. I added a modal segue from a button to a view controller. I then added some steps to prepareForSegue (and checked I had named the segue correctly). I have done this a few other times with no problem.
Now, when I click the button, the modal window opens, but the prepareForSegue does not fire. I tried putting a log statement in the prepareForSegue before it even checks the description of the label (so theoretically it should fire for any segue). But I get nothing logged.
Any ideas?
Connecting a segue from a button to the next controller is the correct way to connect it, just remember that prepareForSegue: is called on the VC that owns the button not the incoming controller. You get the incoming controller by calling [segue destinationViewController].
Well I found the rookie error I suspected. I duplicated a VC and forgot to set it's class to my new VC class.
Wire up the Segue to the VC not the button. Then in the touchUpInside event, put
[self performSegueWithIdentifier:#"segueid" sender:nil];
I almost always wire the segue up to either the VC or a tableviewcell (if I am using a static cell TV)
You should set cell's reuse identifier set before segue is called.
I tried lots of solutions like above
and checked VC settings
but didn't set the prototype cell's reuse identifier.
Only after I set this to "Cell" , it worked finally.

Resources