iphone - UIAlertView 不起作用

标签 iphone ios ios6 uialertview

我有一个带有两个按钮的警报 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/

相关文章:

iphone - 如何在iPhone中实现VoIP+SIP?

iphone - 通过检测 URL scheme 替换本地资源

ios - 自定义图像过滤器

iphone - UIActivityViewController 和 UIActivityItemSource 中用于操作的初始文本和 Papercut URL?

ios - 想要在开发设备上从 iOS 7 返回到 iOS 6

iphone - 致命的 'section too large, can' t 在 gcc 中编码内存地址(iPhone 应用程序)

iphone - 当用户触摸 iPhone 中的 super View 时,如何实现关闭 subview ?

ios - 如何在 UIView 中正确设置 ImageView 的 ContentMode?

ios - Xcode Phonegap 构建错误 : No such file or directory

iphone - 如何从 objective-c 在 iPhone 上启动 map 应用程序