检测单击uitextview上的nsurl [英] Detect Click on nsurl on uitextview
本文介绍了检测单击uitextview上的nsurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的textview中有一个网址,当我们点击此网址时,会在默认的Safari中打开此网址。我想检测这个事件。我也试过这个
I have a URL in my textview and when we click on this url it opens this url in default safari. and I want to detect this event. I also tried this
但它不适合我。任何人都可以建议我如何做到这一点。为我提供一个示例。
but its not working for me. can any one suggest me how i do this. Provide me a sample for this.
我的应用程序deligate是UIResponder类型。
My application deligate is UIResponder type.
推荐答案
其他答案按预期工作。
创建新文件
,选择 Objective-C类
- 类:
MyApplication
- 子类:
UIApplication
- Class:
MyApplication
- Subclass of:
UIApplication
将此代码粘贴到中。 m
文件:
- (BOOL)openURL:(NSURL *)url {
if ([self handleOpenURL:url])
return YES;
else
return [super openURL:url];
}
- (BOOL)handleOpenURL:(NSURL*)url {
NSLog(@"my url handler");
return YES;
}
接下来打开你的 main.m
并更改第三个参数
next open your main.m
and change the third parameter
return UIApplicationMain(argc, argv, nil, NSStringFromClass([SampleAppDelegate class]));
到 UIApplication
-subclass name
to your UIApplication
-subclass name
return UIApplicationMain(argc, argv, @"MyApplication", NSStringFromClass([SampleAppDelegate class]));
这篇关于检测单击uitextview上的nsurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文