我有一个带有两个按钮的警报 View ,但这些按钮不会打开网址。我不知道错误。请帮忙。
代码如下:
-(IBAction)showAlertView {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Obrir en..."
message:@"Es pot requirir la aplicació de Google Maps"
delegate:self
cancelButtonTitle:@"Millor no..."
otherButtonTitles:@"Mapes",@"Google Maps",nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Mapes"])
{
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = @"http://maps.apple.com/?q=Plaça+del+Rei+43003+Tarragona";
NSURL *ourURL = [NSURL URLWithString:ourPath];
[ourApplication openURL:ourURL];
}
if([title isEqualToString:@"Google Maps"])
{
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = @"comgooglemaps://?daddr=Plaça+del+Rei+43003+Tarragona&directionsmode=walking";
NSURL *ourURL = [NSURL URLWithString:ourPath];
[ourApplication openURL:ourURL];
}
}
最佳答案
我认为地址中的特殊字符 (ç) 会使 NSURL 失效。尝试使用 NSString 的 stringByAddingPercentEscapesUsingEncoding:
方法对其进行编码,然后再将其传递给 NSURL 初始值设定项。
关于iphone - UIAlertView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18069430/