我有一个UIwebView,它在网页中有一些链接。我想要一个特定的链接来打开一个警告模式,如图像#1
此外,如何使用下面的代码制作这样的东西 - (图像#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 :(得分:0)
您需要先为网络视图协议注册视图控制器。
然后在你的视图控制器实现web视图的委托方法确实开始加载并检查被调用的URL并使用if else检查相应地执行任务
这是代表参考:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/
从我的手机回答。赦免语法。
希望这有帮助。