user1486548
user1486548

Reputation: 1201

iOS Dev: Segue by pressing a button in an Alert?

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.

Upvotes: 0

Views: 1501

Answers (3)

iNeal
iNeal

Reputation: 1729

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

Upvotes: 3

Ravi
Ravi

Reputation: 8309

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

Upvotes: 1

Dan F
Dan F

Reputation: 17732

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

Upvotes: 0

Related Questions