我搜索了Stack实现多个alertViews
的方法。大多数答案都是使用标签。这种方式效果很好,除了一个巨大的东西 - 取消按钮!当alertView
弹出时,无论您点按“取消”还是“ yourButtonTitle ”,您的操作都会完成。有没有办法取消带有标签的alertView
?
这是我的代码:
#define TAG_ONE 1
#define TAG_TWO 2
- (IBAction)someButton1 {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Call" message:@"Call number?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];
alertView.tag = TAG_ONE;
[alertView show];
}
- (IBAction)someButton2 {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Log Out?" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes", nil];
alertView.tag = TAG_TWO;
[alertView show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == TAG_ONE) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:101-101-1010"]];
} else if (alertView.tag == TAG_TWO){
[PFUser logOut];
[self performSegueWithIdentifier:@"showLogin" sender:self];
}
}
答案 0 :(得分:1)
您只能为TAG
设置UIAlertview
,但您可以使用button
Index
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == TAG_ONE) {
if(alertView.cancelButtonIndex == buttonIndex){
// Do cancel
}
else{
// Do the success thing
}
}
else if (alertView.tag == TAG_TWO) {
// same thing followed
}
}
buttonIndex == 0 //确定, buttonIndex == 1 //取消
答案 1 :(得分:0)
在询问if (alertView.cancelButtonIndex == buttonIndex){
// Do cancel
}
if (alertView.tag == TAG_ONE) {