2013-07-27 59 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你爲什麼取消選中我的答案? –