我发出了一个警告:
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"mymaths.co.uk" message:@"This is a great website for maths exercises!! Have fun!!\n\rIf you prefer to view the website in Safari just press \"Safari\"" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: @"Safari",nil];
[alert1 show];如您所见,我的第二个按钮名为"Safari",它是通过以下代码委托的:
-(void) alertView: (UIAlertView *)alert1: clickedButtonAtIndex:(NSInteger)buttonIndex{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"]];}
但是现在如果我点击Ok (取消按钮),它会打开safari,如果我点击Safari,它也会打开safari。如果我写道:
-(void) alertView: (UIAlertView *)otherButtonTitles Safari: clickedButtonAtIndex:(NSInteger)buttonIndex{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"]];}
两个按钮都取消。我该如何解决这个问题呢?目的是按“确定”取消,并按" safari“打开safari
发布于 2012-02-19 02:15:57
在下面的函数中处理带有按钮索引的警报视图委托,
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
NSLog(@"Cancel");
}
else
{
NSLog(@"Safari");
}
}发布于 2012-02-19 02:33:30
这是我为我的项目所做的。
alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error Title", nil) message:authMessage delegate: self cancelButtonTitle: NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Captcha Required Button", nil), nil];
alert.tag = captchaalert;我为警报设置了一个标签属性,以防当您单击它们时需要打开Safari的人不止一个。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == captchaalert){
if(buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://accounts.google.com/DisplayUnlockCaptcha"]];
}
}
}希望这能有所帮助
https://stackoverflow.com/questions/9343443
复制相似问题