开发者

open URL in UITextView in a modal view controller

开发者 https://www.devze.com 2023-03-05 19:04 出处:网络
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 UIViewContro

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:

  1. Extracting the URL from the UITextView
  2. 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 开发者_如何学Golink 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
0

精彩评论

暂无评论...
验证码 换一张
取 消