- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0) //**Here is your ok button index**
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginViewController *controller=[storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.navigationController pushViewController:controller animated:YES];
}
}
如上方法是在IOS 8棄用,對於那些需要使用alertcontroller代替alertview如下
UIAlertController * alertController= [UIAlertController
alertControllerWithTitle:@"App name"
message:@"Update success"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel action");
}];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginViewController *controller=[storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.navigationController pushViewController:controller animated:YES];
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
'UIAlertView'已棄用,以'UIAlertController'這是很多在添加操作的按鈕更靈活的替換。您應該使用它。 – Fogmeister
你試過我的回答嗎? –