[英]UIWebView and navigation controller
How can I tell my UIWebView
to open links in a new View , using a UINavigationController
? 如何使用UINavigationController
告诉我的UIWebView
在新视图中打开链接?
I found this thread, but ima little confused of where to implement that piece of code (im new to objective-C/IPhone) 我找到了这个帖子,但是我很想知道在哪里实现那段代码(我是Objective-C / IPhone的新手)
Clicking a link in UIWebView pushes onto the NavigationView stack 单击UIWebView中的链接将推送到NavigationView堆栈
my view just contains a simple WebView
with a UINavigationController
on top 我的视图只包含一个带有UINavigationController
的简单WebView
#import <UIKit/UIKit.h>
@interface ContactViewController : UIViewController {
IBOutlet UIWebView *webView1;
}
@property (nonatomic, retain) UIWebView *webView1;
Here are steps assuming your view controller (that houses the webview) is already within a navigation controller. 假设您的视图控制器(包含webview)已经在导航控制器中,这里有一些步骤。
Within the .h - ensure your view controller conforms to the webview delegate 在.h内 - 确保您的视图控制器符合webview委托
UIViewController <UIWebViewDelegate>
Within the .m - add the following code (or just implement this method with whatever logic you want) 在.m中 - 添加以下代码(或者只使用您想要的任何逻辑实现此方法)
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
YourNextViewController *ynvc = [[[YourNextViewController alloc] initWithNibName:@"YourNextViewController" bundle:nil] autorelease];
ynvc.ivar1 = value1;
ynvc.ivar2 = value2;
UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
[[self navigationItem] setBackBarButtonItem:backButton];
[self.navigationController pushViewController:ynvc animated:YES];
return NO;
}
return YES;}
I'm pretty new to objective C / iPhone too, but what I would try,.. 我对客观的C / iPhone也很陌生,但我会尝试,...
Is creating a new viewController for your webview and push it in your UINavigator 是为您的webview创建一个新的viewController并将其推送到您的UINavigator中
yourWebViewController *y = [[yourWebViewController alloc] init];
[self.navigationController pushViewController:y animated:YES];
[y release];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.