0

I've been searching for a few hours and haven't found any answers, so I would really appreciate your help!

I am designing an app and need to segue to a different view controller when a button in an alert is pressed. I already have the alert set up, but just need the code to segue to a new view.

Dan F
  • 17,654
  • 5
  • 72
  • 110
user1486548
  • 1,201
  • 4
  • 15
  • 22

3 Answers3

3

Try this. create alertview first.

UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Message"  message:@"Open New controller?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];
[alertView show];
[alertView release];

Implement the AlertView Delegate Method

#pragma mark AlertView Delegate
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != alertView.cancelButtonIndex)
    {
        Viewcontroller *vc = [[UIViewcontroller alloc] initWithNib:@"Viewcontroller"];
        [self presentModalViewController:vc];
        [vc release];
    }
}
iNeal
  • 1,729
  • 15
  • 23
1

Implement the UIAlertViewDelegate and add the method alertView:clickedButtonAtIndex:. Once the right button is clicked, call the method to segue into the new view.

Ravi
  • 7,929
  • 6
  • 38
  • 48
0

Implement UIAlertViewDelegate and then you get a callback with which button was pressed when the alert was dismissed. Simply call performSegueWithIdentifier in there.

More details at the UIAlertViewDelegate protocol reference

Dan F
  • 17,654
  • 5
  • 72
  • 110