我有两个场景。第一个有一个UIWebView。让我们说用户点击这个链接:
<a href="startSecondScene">start second scene</a>
第二个应该没有在第一个中加载链接。
ViewController.m代码:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *urlString = @"http://www.autoblog.com/";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[_udazzWebView loadRequest:urlRequest];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:0)
您可以使用UIWebViewDelegate中的方法:
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL.absoluteString isEqualToString:@"startSecondScene"]) {
//go to the second scene
return NO;
}
return YES;
}
不要忘记_udazzWebView.delegate = self;
方法中的-viewDidLoad
。
你可以像这样推送新场景:
SecondViewController* _vc = [SecondViewController new];
[self.navigationController pushViewController:_vc animated:YES];
有关navigationController
的更多信息,请参阅文档:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/index.html#//apple_ref/doc/c_ref/UINavigationController
希望它会有所帮助。