当它们出现时,我有大约 4 个具有不同标准的警报 View 。在所有 4 个 View 中,右键应该总是做同样的事情。
我使用下面的代码来尝试说如果 buttonIndex == 1,做点什么。
目前,它仅适用于我的一个警报 View 。其他人只是最终关闭警报 View 并且从不运行 IF buttonIndex == 1 的代码。
任何想法,将不胜感激。
if (a==1) {
NSString *message = [[NSString alloc] initWithFormat:
@"Only $%@!",dollas.text];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
@"Really?!"
message:message
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:@"Facebook",nil];
[alert show];
[alert release];
[message release];
}
else if (a==2) {
NSString *message = [[NSString alloc] initWithFormat:
@"Somone just paid you $%@", dollas.text];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
@"Swish!"
message:message
delegate:nil
cancelButtonTitle:@"Close"
otherButtonTitles:@"Facebook",nil];
[alert show];
[alert release];
[message release];
}
和代表:
- (void)alertView:(UIAlertView *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1)
{
do.stuff;
}
最佳答案
您应该将委托(delegate)设置为 self
所以该方法被调用。
IE -
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
@"Really?!"
message:message
delegate:self //SELF
cancelButtonTitle:@"Close"
otherButtonTitles:@"Facebook",nil];
关于ios - 将 buttonIndex 与多个警报 View 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17386695/