2015-08-09 50 views
0

我有一个UIwebView,它在网页中有几个链接。我想一定链接图像#打开警报模式类似1Objective-C在Safari和Alert对话框中打开链接

另外,如何可以使用下面的代码,以使这样的事情 - (IMAGE 1#)http://screenshot.it.sftcdn.net/blog/it/2014/01/Block-user-03-Tasto-Block-378x568.png在Objective-C

- (IBAction)showAlert:(id)sender 
{ 
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Open In..." 
       message:@"Which app would you like to open?" 
      preferredStyle:UIAlertControllerStyleActionSheet]; 

    UIAlertAction *mapsAction = [UIAlertAction actionWithTitle:@"Maps" 
      style:UIAlertActionStyleDefault 
      handler:^(UIAlertAction *action) { 
       if (![self openURLForString:@"maps://"]) { 
        NSLog(@"Couldn't Open Maps"); 
       } 
      }]; 
    UIAlertAction *youtubeAction = [UIAlertAction actionWithTitle:@"YouTube" 
      style:UIAlertActionStyleDefault 
      handler:^(UIAlertAction *action) { 
       if (![self openURLForString:@"http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) { 
        NSLog(@"Couldn't Open YouTube"); 
       } 
      }]; 
    UIAlertAction *messagesAction = [UIAlertAction actionWithTitle:@"Messages" 
      style:UIAlertActionStyleDefault 
      handler:^(UIAlertAction *action) { 
       if (![self openURLForString:@"sms://"]) { 
        NSLog(@"Couldn't Open Messages"); 
       } 
      }]; 
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" 
      style:UIAlertActionStyleCancel 
     handler:nil]; 

    [alertController addAction:mapsAction]; 
    [alertController addAction:youtubeAction]; 
    [alertController addAction:messagesAction]; 
    [alertController addAction:cancelAction]; 

    [self presentViewController:alertController animated:YES completion:nil]; 
} 

- (BOOL)openURLForString:(NSString *)urlString { 
    NSURL *url = [NSURL URLWithString:urlString]; 
    if ([[UIApplication sharedApplication] canOpenURL:url]) { 
     [[UIApplication sharedApplication] openURL:url]; 
     return YES; 
    } 
    return NO; 
} 

在第二个UIwebView中打开链接的“报告不适当”打开了父级网络视图和“共享”,在Safari中打开。 (忽略“复制链接/ URL”)

+0

目前还不清楚你在问什么......你问如何执行一个模态视图控制器转换来呈现一个新的web视图? – Stuart

+0

@stuart#1)我想在uiwebview的网页中打开一个警报模式,如图像#1#2中的某个链接)图像#1中的“报告不适当”是第二个UIwebView中的链接打开时打开在父级webview和“共享”之上打开Safari。 (忽略“复制链接/网址”) –

+0

请在下面查看我的答案,并告诉我它是否可以使用。谢谢。 –

回答