在模态视图控制器中打开 UITextView 中的 URL
我有一个 UITextView,其中包含一些字符串和 URL 的文本组合。现在,当我单击 URL 时,它会在 Safari 中打开它。我想做的是在作为 modalViewController 推送的新 UIViewController 中打开它。这有两个问题:
- 从 UITextView 中提取 URL 拦截
- 对 safari 的调用以打开它,然后推送 modalViewController 来显示它 在网络视图中。
我知道以前已经这样做过,例如在 tweetbot 应用程序中。它会在导航栏中打开链接,您可以在其中返回到上一个视图。像这样的事情对我来说也很好。有什么指示可以做什么吗?
当您必须在浏览器中打开链接并且无法再次返回应用程序时,这对用户来说很烦人。
更新:
我遵循了这篇文章的链接中给出的建议,但在更改后我的视图仅更改为白屏:
#import <Foundation/Foundation.h>
@class CVore;
@protocol CVoreDelegate
- (void) withURL:(NSURL *)url;
@end
@interface CVore : UIApplication {
id <CVoreDelegate> delegate;
}
@property (nonatomic, assign) id <CVoreDelegate> delegate;
@end
#import "CVore.h"
@implementation CVore
@synthesize delegate;
- (BOOL)openURL:(NSURL *)url{
if (url){
[self.delegate withURL:url];
return YES;
}
return NO;
}
@end
I have a UITextView which has a text combination of some strings and URL. Right now when I click on the URL it opens it up in safari. What I want to do instead is to have it open in a new UIViewController pushed as a modalViewController. There are two problems with this:
- Extracting the URL from the UITextView
- Intercepting the call to safari to open it up and instead push a modalViewController to display it
in a webview.
I know it has been done before, for example in the tweetbot app. It opens up the link in a navigation bar where you can go back to the previous view. Something like this is also fine with me. Any pointers on what to do?
It's annoying for a user when you have to open up the link in a browser and you can't go back to the app again.
UPDATE:
I followed the suggestion given in the link to this post but after changing that my view just changes to a white screen:
#import <Foundation/Foundation.h>
@class CVore;
@protocol CVoreDelegate
- (void) withURL:(NSURL *)url;
@end
@interface CVore : UIApplication {
id <CVoreDelegate> delegate;
}
@property (nonatomic, assign) id <CVoreDelegate> delegate;
@end
#import "CVore.h"
@implementation CVore
@synthesize delegate;
- (BOOL)openURL:(NSURL *)url{
if (url){
[self.delegate withURL:url];
return YES;
}
return NO;
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论