【发布时间】:2011-06-28 16:26:02
【问题描述】:
我想知道如何制作 2 个 UIAlertView,带有 3 个按钮,UIAlertViews(2) 需要不同,选项和操作......如何???
【问题讨论】:
-
您已经尝试过什么?你在实现它时到底有什么问题?
标签: iphone xcode uialertview ipod-touch
我想知道如何制作 2 个 UIAlertView,带有 3 个按钮,UIAlertViews(2) 需要不同,选项和操作......如何???
【问题讨论】:
标签: iphone xcode uialertview ipod-touch
只需在 alertviews(4) 委托方法中检查 2 哪个 alertviews 负责要调用的方法(1)。
【讨论】:
试试这个:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" message:@"Message." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Button 2", @"Button 3", nil];
alert.tag = 1;
[alert show];
然后对下一个alertView做同样的事情,只是把tag改成2
然后运行这个方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alert.tag == 1) {
//the alert tag 1 was just closed - do something
}
}
另外 - 确保包含 UIAlertViewDelegate
【讨论】:
UIAlertview 委托在 ios 9.0 中已弃用
此外,当您添加超过 2 个按钮时,它们将由 IOS 垂直分配。
你可以简单地使用 UIAlertController
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:[[[NSBundle mainBundle] infoDictionary]
objectForKey:@"CFBundleDisplayName"]
message:@"share via"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* fbButton = [UIAlertAction
actionWithTitle:@"Facebook"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
// Add your code
}];
UIAlertAction* twitterButton = [UIAlertAction
actionWithTitle:@"Twitter"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
// Add your code
}];
UIAlertAction* watsappButton = [UIAlertAction
actionWithTitle:@"Whatsapp"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
// Add your code
}];
UIAlertAction* emailButton = [UIAlertAction
actionWithTitle:@"Email"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
// Add your code
}];
UIAlertAction* cancelButton = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Handel no, thanks button
}];
[alert addAction:fbButton];
[alert addAction:twitterButton];
[alert addAction:watsappButton];
[alert addAction:emailButton];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
【讨论】: