我用三个按钮创建了一个警报视图——“注册”、“捐赠”、“取消”——当你点击注册或捐赠时,safari 应该打开特定的网站。但是,当我打开应用程序并单击任何按钮时,safari 不会打开或执行任何操作,并且这些按钮就像取消按钮的不同版本一样工作。这是我的代码:
在 BlahBlah.h 中:
@interface BlahBlah: UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
}
@end
在 BlahBlah.m 中:
#define donate_tag 0
#import "BlahBlah.h"
@implementation BlahBlah
...
- (void) donate {
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Donate"
message:@"Function doesn't work yet :(" delegate:nil cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Sign Up",@"Donate",nil];
alert2.tag = donate_tag;
[alert2 show];
[alert2 release];
}
...
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alertView.tag == donate_tag && buttonIndex == 1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
else if(alertView.tag == donate_tag && buttonIndex == 2){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.yahoo.com"]];
}
}
...
@end