第一.遵循webView的代理
@interface SocialContactController ()<UIScrollViewDelegate,UIWebViewDelegate>{
BOOL isfirst;
}
第二.记录url
@property (strong,nonatomic) NSString *urlS;
第三.webView使用常规设置
- (void)viewDidLoad {
[super viewDidLoad];
if (!_isRootNavJump) {
[self leftButtonWithImage:[UIImage imageNamed:@"back_button.png"]
highlightImage:[UIImage imageNamed:@"back_button.png"]
title:nil
size:CGSizeMake(25, 25)
action:@selector(back)
target:self];
}
[self setupTitle:_titleName];
[self rightButtonWithImage:nil
highlightImage:nil
title:@""
size:CGSizeMake(70,40)
action:nil
target:self];
NSURLRequest *request;
if (_URLString) {
request = [NSURLRequest requestWithURL:[NSURL URLWithString:_URLString]];
}else{
self.urlS = @"此处Url根据服务器提供的地址,不便透露]";
request = [NSURLRequest requestWithURL:[NSURL URLWithString:_urlS]];
}
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,WIDTH, HEIGHT-64)];
[self.webView loadRequest:request];
self.webView.scrollView.showsHorizontalScrollIndicator = NO;
self.webView.delegate = self;
self.webView.scrollView.delegate = self;
self.webView.scrollView.bounces = YES;
_webView.scalesPageToFit = YES;
[self.view addSubview:self.webView];
}
第四:在WebView的代理方法截取请求的URL地址,进行截取
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if (_isRootNavJump) {
NSString *urlStr = request.URL.absoluteString;
if ([urlStr isEqualToString:self.urlS]) {
return YES;
}else {
NSRange range = [urlStr rangeOfString:@"data="];
if (range.length > 0)
{NSString *str = [urlStr substringFromIndex:range.location + range.length];
CompanySocialVC *company = [[CompanySocialVC alloc] init];
company.parameterStr = str;
company.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:company animated:YES];
// [self.navigationController ]
NSLog(@"%@--- url",str);
return NO;
}}}return YES;}
最后,就可以拿到截取的参数去请求服务器拿数据了,一般服务器那边会处理解码,我们只需要传一个字符串给服务器就行了