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
向我們展示你的'alertView執行:clickedButtonAtIndex:'或'alertView:didDismissWithButtonIndex:'方法。 – 2013-07-27 16:45:40