问题描述
我发现这个线程符合我的问题:单击 UIWebView 中的链接会推送到 NavigationView 堆栈
I found this thread which matches my problem: Clicking a link in UIWebView pushes onto the NavigationView stack
但是,以下情况有所不同:我没有使用导航控制器,而是使用基于视图的应用程序在按下相应的按钮时手动切换到不同的视图控制器.我没有使用链接,而是使用 onClick 方法来检测用户何时单击 UIWebView 上的某些内容并尝试使用新的 UIWebView 打开新的 ViewController.
However, the following situations are different:Instead of using a navigationController, I am using a View Based application to manually switch to different viewcontroller when corresponding buttons are pressed.Rather than using links I am using onClick method to detect when a user clicks on something on a UIWebView and trying to open a new ViewController with a new UIWebView.
相同的代码是否有效?我是否需要进行一些更改?
Will the same code work or do i have to make some changes?
推荐答案
你需要做一些修改
第一:onClick
时,您必须将当前页面重定向到新位置例如,此位置将是 MYLocation://GoThere
1st:when onClick
, you will have to redirect your current page to a new locationThis location for example will be MYLocation://GoThere
第二:更新 shouldStartLoadWithRequest
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
//Check if special link
if ( [ urlString isEqualToString: @"MYLocation://GoThere" ] ) {
//Here present the new view controller
MyViewController *controller = [[MyViewController alloc] init];
[self presentViewController:controller animated:YES];
return NO;
}
return YES;
}
这篇关于单击 UIWebView 上的链接时打开新的 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!