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

十年热恋 提交于 2019-12-10 11:50:06

问题


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.


回答1:


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



回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/11957433/ios-dev-segue-by-pressing-a-button-in-an-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!