Uiwebview 导航和重定向

发布于 2024-11-08 22:59:54 字数 132 浏览 0 评论 0原文

文本视图中出现的任何链接都会自动突出显示,并作为链接应用并被重定向到 safari,但我希望将其重定向到我为浏览而创建的 Uiwebview。这样我就不会离开我的应用程序。那么我如何将我的页面链接到 uiwebview 页面。

谢谢。

Any link which appears in a textview are automatically highlighted and apperas as a link and are being redirected to safari, but instead i want it to be redirected to a Uiwebview which i create for browsing. so that i won't be navigated away from my application. So how can i link my page to a uiwebview page.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱桃奶球 2024-11-15 22:59:54

创建一个加载 .xib 的 UIWebView 类 (WebViewController),如下所示:

#import <UIKit/UIKit.h>

@interface WebViewController : UIViewController
{

}

@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, copy) NSString *urlString;

@end

然后在实现文件中,实现此方法:

-(void)viewWillAppear:(BOOL)animated
{
    NSURL *url = [NSURL URLWithString:urlString_];

    NSURLRequest *req = [NSURLRequest requestWithURL:url];

    [[self webView] loadRequest:req];
    NSLog(@"url requested");

    [[self navigationController] setNavigationBarHidden:NO animated:YES];
    NSLog(@"showing nav");
    [super viewWillAppear:animated];
}

然后在实例化 Web 视图的委托类中,向 WebViewController 提供 url 并将其推送到导航控制器堆栈:(

netView.urlString = @"http://www.morrisjenkins.com/home";
[[self navigationController] pushViewController:netView animated:YES];
[netView release];
netView = nil;

假设您将委托类添加到应用程序委托中的 UINavigationController 中)

UIViewController *webController = [[WebViewDelegateController alloc] init];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:webController];

Create a UIWebView class (WebViewController) that loads a .xib and looks something like this:

#import <UIKit/UIKit.h>

@interface WebViewController : UIViewController
{

}

@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, copy) NSString *urlString;

@end

Then in the implementation file, implement this method:

-(void)viewWillAppear:(BOOL)animated
{
    NSURL *url = [NSURL URLWithString:urlString_];

    NSURLRequest *req = [NSURLRequest requestWithURL:url];

    [[self webView] loadRequest:req];
    NSLog(@"url requested");

    [[self navigationController] setNavigationBarHidden:NO animated:YES];
    NSLog(@"showing nav");
    [super viewWillAppear:animated];
}

Then in the delegate class that instantiates the web view, feed WebViewController the url and push it to the navigation controller stack:

netView.urlString = @"http://www.morrisjenkins.com/home";
[[self navigationController] pushViewController:netView animated:YES];
[netView release];
netView = nil;

(This assumes that you added the delegate class to a UINavigationController in the app's delegate)

UIViewController *webController = [[WebViewDelegateController alloc] init];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:webController];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文