我尝试使用以下代码覆盖网址:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *urlString = @"http://www.google.com/";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[_udazzWebView loadRequest:urlRequest];
NSLog(@"log");
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest: (NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"log2");
//use NSURLRequest object request , to manage the request.
NSURL *urL=request.URL;
NSString *urlStr=[urL absoluteString];
NSLog(@"URLL %@",urlStr);
if([urlStr isEqualToString:@"PostPicPopUp"]){
NSLog(@"log3");
}
return YES;
}
Log2不会出现在控制台中。我猜这与替换NSURLRequest
中的viewDidLoad
有关,但我不知道该怎么做。
答案 0 :(得分:0)
在我看来,你只是缺少UIWebView委托初始化
- (void)initWebViewWithRect:(CGRect)rect {
self.webView = [[UIWebView alloc] initWithFrame:rect];
self.webView.backgroundColor = [UIColor whiteColor];
self.webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.webView.opaque=NO;
self.webView.userInteractionEnabled=YES;
self.webView.delegate=self;
[self cleanSubViews];
}
您的UIWebView应该定义为
@interface MXMBaseWebView()<UIWebViewDelegate, UIScrollViewDelegate, MXMWebViewProgressDelegate> {
CAGradientLayer *shadowLayer;
MXMWebViewProgressView *_progressView;
MXMWebViewProgress *_progressProxy;
UIRefreshControl *_refreshControl;
}
@property(nonatomic, strong) UIWebView *webView;
@end
所以你会做像
这样的电话[self.webView loadRequest: [NSURLRequest requestWithURL:url]];
此时一切都应该正常工作。