TrafficRulesViewController.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // TrafficRulesViewController.m
  3. // Miaxis
  4. //
  5. // Created by tongjun on 14-1-20.
  6. // Copyright (c) 2014年 tongjun. All rights reserved.
  7. //
  8. #import "TrafficRulesViewController.h"
  9. #import <WebKit/WebKit.h>
  10. @interface TrafficRulesViewController ()<WKNavigationDelegate>
  11. {
  12. WKWebView* webView;
  13. }
  14. @end
  15. @implementation TrafficRulesViewController
  16. -(void)viewWillAppear:(BOOL)animated
  17. {
  18. [super viewWillAppear:animated];
  19. self.navigationController.navigationBarHidden = NO;
  20. }
  21. - (void)viewDidLoad
  22. {
  23. [super viewDidLoad];
  24. [self.view setBackgroundColor:[UIColor whiteColor]];
  25. NSArray *urls=[myDelegate.url componentsSeparatedByString:@";"];
  26. [self setTitle:[urls objectAtIndex:0]];
  27. if ([urls[0] isEqualToString:@"帮助"]) {
  28. [self configNavigationBar];
  29. }else{
  30. [self configNavigationBar];
  31. }
  32. webView=[[WKWebView alloc]initWithFrame:kFrame];
  33. webView.height = kSize.height-kNavOffSet;
  34. webView.backgroundColor = [UIColor clearColor];
  35. webView.navigationDelegate = self;
  36. [self.view addSubview:webView];
  37. [self loadHtml];
  38. }
  39. - (void)didReceiveMemoryWarning
  40. {
  41. [super didReceiveMemoryWarning];
  42. }
  43. #pragma mark -
  44. -(void)loadHtml
  45. {
  46. NSArray *urls=[myDelegate.url componentsSeparatedByString:@";"];
  47. NSString *htmlPath;
  48. NSURL *url;
  49. //NSLog(@"web----html----%@",urls);
  50. if (urls.count > 2) {
  51. htmlPath = urls[1];
  52. url = [NSURL URLWithString:htmlPath];
  53. if (![Util connectedToNetWork]) {
  54. showMsgUnconnect();
  55. return;
  56. }
  57. }else{
  58. htmlPath = [[NSBundle mainBundle] pathForResource:[urls objectAtIndex:1] ofType:@"html"];
  59. url = [NSURL fileURLWithPath:htmlPath isDirectory:NO];
  60. }
  61. [MBProgressHUD showLoadToView:self.view];
  62. [webView loadRequest:[NSURLRequest requestWithURL:url]];
  63. }
  64. #pragma mark -
  65. // 页面加载失败时调用
  66. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{
  67. [MBProgressHUD hideHUDForView:self.view];
  68. }
  69. // 页面加载完毕时调用
  70. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  71. [MBProgressHUD hideHUDForView:self.view];
  72. }
  73. @end