[英]UIWebView and navigation controller
如何使用UINavigationController
告诉我的UIWebView
在新视图中打开链接?
我找到了这个帖子,但是我很想知道在哪里实现那段代码(我是Objective-C / IPhone的新手)
单击UIWebView中的链接将推送到NavigationView堆栈
我的视图只包含一个带有UINavigationController
的简单WebView
#import <UIKit/UIKit.h>
@interface ContactViewController : UIViewController {
IBOutlet UIWebView *webView1;
}
@property (nonatomic, retain) UIWebView *webView1;
假设您的视图控制器(包含webview)已经在导航控制器中,这里有一些步骤。
在.h内 - 确保您的视图控制器符合webview委托
UIViewController <UIWebViewDelegate>
在.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;}
我对客观的C / iPhone也很陌生,但我会尝试,...
是为您的webview创建一个新的viewController并将其推送到您的UINavigator中
yourWebViewController *y = [[yourWebViewController alloc] init];
[self.navigationController pushViewController:y animated:YES];
[y release];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.