Make button it UIAlertView perform Segue
ios, segue, uialertview, uistoryboard, uistoryboardsegue
Solution
Yeah, it's not very obvious at first, you need to create a manual segue.
Select the ViewController that will do the pushing (I'm the one who pushes), and connect manual to the pushed view controller (The Pushed View controller).
iOS 8+ with Swift
Select the newly created segue, and give it a name (in my case is `"segue.push.alert"`, long name for logging), and call the perform segue in the action of the alert, like:
let alert = UIAlertController(title: "My Alert", message: "Be Alerted. This will trigger a segue.", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Segue", style: .Default, handler:
{
[unowned self] (action) -> Void in
self.performSegueWithIdentifier("segue.push.alert", sender: self)
}))
presentViewController(alert)
`[unowned self]` should be handled with care, if the view controller can deallocate while the action is happening, you're better off with `[weak self]` and then doing `self?.performSegue...` if deallocation can occur.
Old Answer
Now, from a view controller you can simply call `performSegueWithIdentifier:sender:`, in your case
// Using enums is entirely optional, it just keeps the code neat.
enum AlertButtonIndex : NSInteger
{
AlertButtonAccept,
AlertButtonCancel
};
// The callback method for an alertView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)index
{
if (index == AlertButtonAccept)
{
[self performSegueWithIdentifier:@"segue.push.alert" sender:self];
}
}
The advantage of having the segues in this way (instead of being directly coded), is that you can still have that nice overview of your application flow, having intermixed coded segues and storyboard-loaded segues kinda defeats the purpose.
Problem
I have created a `UIAlertView` for an action which gives me 2 options. I want the user to be able to click on a button and have it perform a Segue. Here's the code I have so far: ``` - (IBAction)switchView:(id)sender { UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Please Note" message:@"Hello this is my message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Option 1", @"Option 2", nil]; [myAlert show]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex]; if ([buttonTitle isEqualToString:@"Option 1"]) { } } ```