js调用oc方法 UIWebView 跳 到另一个UIWebView
2015-08-03 16:59
405 查看
// // BusinessListViewController.h // LouLiLouWai // // Created by jouhu on 15/7/31. // Copyright (c) 2015年 jouhu. All rights reserved. // #import <UIKit/UIKit.h> @interface BusinessListViewController : UIViewController @property (strong, nonatomic) NSString *urlString; //@property (strong, nonatomic) NSString *titleString; @end
// // BusinessListViewController.m // LouLiLouWai // // Created by jouhu on 15/7/31. // Copyright (c) 2015年 jouhu. All rights reserved. // #import "BusinessListViewController.h" #import "BusinessList2ViewController.h" #import "MBProgressHUD.h" @interface BusinessListViewController ()<UIWebViewDelegate> @property (weak, nonatomic) IBOutlet UIWebView *webView; @end @implementation BusinessListViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.automaticallyAdjustsScrollViewInsets = NO; self.edgesForExtendedLayout = UIRectEdgeNone; UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] init] ; backBarButtonItem.title = @"" ; self.navigationItem.backBarButtonItem = backBarButtonItem ; self.webView.delegate = self; NSURL *url = [NSURL URLWithString:self.urlString]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; [self.webView loadRequest:urlRequest]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // self.navigationItem.title = self.titleString; // NSURL *url = [NSURL URLWithString:self.urlString]; // NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; // [self.webView loadRequest:urlRequest]; } //- (void)viewDidDisappear:(BOOL)animated //{ // //清除缓存 // [self.webView loadHTMLString:@" " baseURL:nil]; //} - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSString *urlString = [[request URL] absoluteString]; urlString = [urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"url1String=%@",urlString); // if ([urlString isEqualToString:@"about:blank"]) { // return NO; // } NSArray *urlComps = [urlString componentsSeparatedByString:@"://"]; if([urlComps count] && [[urlComps objectAtIndex:0] isEqualToString:@"protocol"]) { NSArray *arrFucnameAndParameter = [(NSString*)[urlComps objectAtIndex:1] componentsSeparatedByString:@";"]; NSString *funcStr = [arrFucnameAndParameter objectAtIndex:0]; if (1 == [arrFucnameAndParameter count]) { // 没有参数 if([funcStr isEqualToString:@"doFunc1"]) { /*调用本地函数1*/ NSLog(@"doFunc1"); } } else { //有参数的 if([funcStr isEqualToString:@"toActivity"]) { NSLog(@"doFunc2"); [self toActivityWithUrl:[arrFucnameAndParameter objectAtIndex:1] title:[arrFucnameAndParameter objectAtIndex:2] share:[arrFucnameAndParameter objectAtIndex:3]]; } } return NO; } return TRUE; } - (void)webViewDidStartLoad:(UIWebView *)webView { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { if ([error code] != NSURLErrorCancelled){ [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; UIAlertView *alterview = [[UIAlertView alloc] initWithTitle:@"" message:[error localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"好", nil]; [alterview show]; } } - (void)toActivityWithUrl:(NSString *)urlString title:(NSString *)titleString share:(NSString *)shareString { BusinessList2ViewController *businessList2ViewController = [[BusinessList2ViewController alloc] initWithNibName:@"BusinessList2ViewController" bundle:[NSBundle mainBundle]]; [businessList2ViewController setHidesBottomBarWhenPushed:YES]; businessList2ViewController.urlString = [NSString stringWithFormat:@"http://%@",urlString]; businessList2ViewController.navigationItem.title = titleString; businessList2ViewController.shareString = shareString; [self.navigationController pushViewController:businessList2ViewController animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
相关文章推荐
- iOS开发 字符串过滤html标签
- 【Android】开机自启动Service
- 【Android】Service学习之本地服务
- IOS视图位置可能变化解决问题
- php微信服务端的接口程序
- 【Android】Service 生命周期
- 移动端H5页面之iphone6的适配
- Swift学习之路02-类,初始化
- iOS开发最常用的第三方库
- 【Objective-C编程】深入浅出字符串NSString
- Swift学习之路01-基础类型
- Android自定义控件:如何使用自定义的XML属性
- NSDate 判断指定的日期为今天,明天,还是昨天。
- 如何更快捷的设置Android Studio和Eclipse的快捷键一样和代码提示
- Android4.0 Launcher拖拽原理分析(1)
- Android ANR-Thermal condition
- Android屏幕保护KeyguardManager相关内容学习
- spring将service添加事务管理,在applicationContext.xml文件中的设置
- IOS下用Zbar实现摄像头扫描二维码和扫描本地相册二维码
- Android 适配横屏