TRDetailVC.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // TRDetailVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/12/24.
  6. // Copyright © 2015年 JCZ. All rights reserved.
  7. //
  8. #import "TRDetailVC.h"
  9. #import <WebKit/WebKit.h>
  10. @interface TRDetailVC ()<WKNavigationDelegate>
  11. @end
  12. @implementation TRDetailVC
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. [self myInit];
  16. }
  17. - (void)didReceiveMemoryWarning {
  18. [super didReceiveMemoryWarning];
  19. // Dispose of any resources that can be recreated.
  20. }
  21. -(void)myInit
  22. {
  23. [self configNavigationBar];
  24. [self.view setBackgroundColor:[UIColor whiteColor]];
  25. if (_file.length >9 ) {
  26. [self setTitle:[[_file substringToIndex:9] stringByAppendingString:@"..."]];
  27. }else{
  28. [self setTitle:_file];
  29. }
  30. WKWebView* webView=[[WKWebView alloc]initWithFrame:kFrame];
  31. webView.height = kSize.height-kNavOffSet;
  32. webView.navigationDelegate = self;
  33. [self.view addSubview:webView];
  34. NSString *htmlPath;
  35. NSURL *url;
  36. htmlPath = [[NSBundle mainBundle] pathForResource:_file ofType:@"html"];
  37. if (htmlPath && ![htmlPath isEqualToString:@""]) {
  38. url = [NSURL fileURLWithPath:htmlPath isDirectory:NO];
  39. [MBProgressHUD showLoadToView:self.view];
  40. [webView loadRequest:[NSURLRequest requestWithURL:url]];
  41. }else{
  42. ShowMsg(@"未找到该页面");
  43. }
  44. }
  45. #pragma mark -
  46. // 页面加载失败时调用
  47. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error{
  48. [MBProgressHUD hideHUDForView:self.view];
  49. }
  50. // 页面加载完毕时调用
  51. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
  52. [MBProgressHUD hideHUDForView:self.view];
  53. }
  54. @end