2013-07-27 35 views
-1

UIAlertView委托没有被调用。警报显示,但按钮不起作用。我想要一个按钮打开谷歌地图,另一个按钮打开本地地图应用程序。如何在UIAlertView中设置动作?

-(IBAction)showAlertView { 
UIAlertView *alert = [[UIAlertView alloc] 
         initWithTitle:@"Obrir en..." 
         message:@"" 
         delegate:self 
         cancelButtonTitle:@"Millor no..." 
         otherButtonTitles:@"Mapes",@"Google Maps",nil]; 
[alert show]; 
} 
-(void)showAlertView:(UIAlertView *)alert clickedButtonAtIndex (NSInteger)otherButtonTitles 
{ 
NSString *title = [alert buttonTitleAtIndex:otherButtonTitles]; 

if([title isEqualToString:@"Mapes"]) 
{ 
    UIApplication *ourApplication = [UIApplication sharedApplication]; 
    NSString *ourPath = @"http://maps.apple.com/?q=41.11670,1.25812"; 
    NSURL *ourURL = [NSURL URLWithString:ourPath]; 
    [ourApplication openURL:ourURL]; 

} 
if([title isEqualToString:@"Google Maps"]) 
{ 
    UIApplication *ourApplication = [UIApplication sharedApplication]; 
    NSString *ourPath = @"http://maps.apple.com/?q=41.11670,1.25812"; 
    NSURL *ourURL = [NSURL URLWithString:ourPath]; 
    [ourApplication openURL:ourURL]; 
} 
} 
@end 
+0

向我们展示你的'alertView执行:clickedButtonAtIndex:'或'alertView:didDismissWithButtonIndex:'方法。 – 2013-07-27 16:45:40

回答

1

开关:

-(void)showAlertView:(UIAlertView *)alert clickedButtonAtIndex (NSInteger)otherButtonTitles 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
+0

如果它记得检查。 –

+0

使用'-alertView:didDismissWithButtonIndex:'委托方法代替警报视图更“安全”。 – holex

+0

@ user2367043你为什么取消选中我的答案? –