WebViewController.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // WebViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 1/21/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "WebViewController.h"
  9. #import "RAUtils.h"
  10. #import "const.h"
  11. @interface WebViewController ()
  12. @end
  13. @implementation WebViewController
  14. - (void)viewWillAppear:(BOOL)animated
  15. {
  16. [super viewWillAppear:animated];
  17. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  18. }
  19. - (void)viewDidLoad
  20. {
  21. [super viewDidLoad];
  22. // self.edgesForExtendedLayout = UIRectEdgeNone;
  23. // Do any additional setup after loading the view.
  24. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  25. ref.tag = 200 ;
  26. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
  27. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  28. // ref.hidden = true;
  29. [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  30. [self.wkWebview.scrollView addSubview:ref];
  31. self.wkWebview.navigationDelegate = self;
  32. // self.wkWebview.dataDetectorTypes=UIDataDetectorTypeAll;
  33. // self.wkWebview datade
  34. if(!_defaultBarbutton)
  35. {
  36. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  37. style:UIBarButtonItemStylePlain
  38. target:self
  39. action:@selector( onBackClick:)];
  40. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  41. // closeButton.title = @"Close";
  42. // closeButton.tintColor = UIColorFromRGB(0x996633);
  43. self.navigationItem.leftBarButtonItem = closeButton;
  44. }
  45. [self loadcontent];
  46. }
  47. - (void)onBackClick:(UIButton *)sender {
  48. /*
  49. if (self.backItemDismiss)
  50. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  51. [self.navigationController popViewControllerAnimated:FALSE];*/
  52. //如果以下关闭有问题则回滚上面注释代码
  53. if (self.presentingViewController) {
  54. [self dismissViewControllerAnimated:YES completion:nil];
  55. } else {
  56. [self.navigationController popViewControllerAnimated:YES];
  57. }
  58. }
  59. -(void)ReloadData
  60. {
  61. // Count ++ ;
  62. // [mytabelview reloadData];
  63. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  64. [reF endRefreshing];
  65. [self loadcontent];
  66. }
  67. -(void) loadcontent
  68. {
  69. self.mum.hidden=false;
  70. NSURL *url =[NSURL URLWithString:self.url];
  71. DebugLog(@"%@",self.url);
  72. NSURLRequest *request =[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:self.timeout];
  73. // if(self.timeout>0)
  74. // request.timeoutInterval = self.timeout;
  75. [self.wkWebview loadRequest:request];
  76. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  77. }
  78. -(void)changeCell
  79. {
  80. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  81. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  82. if ([self respondsToSelector:@selector(ReloadData)])
  83. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  84. // DebugLog(@"refresh!!!!!!!!");
  85. }
  86. - (void)didReceiveMemoryWarning
  87. {
  88. [super didReceiveMemoryWarning];
  89. // Dispose of any resources that can be recreated.
  90. }
  91. #pragma mark - WKNavigationDelegate
  92. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
  93. {
  94. self.mum.hidden=true;
  95. }
  96. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
  97. {
  98. self.mum.hidden=true;
  99. }
  100. - (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
  101. {
  102. self.mum.hidden=true;
  103. }
  104. /*
  105. #pragma mark - Navigation
  106. // In a storyboard-based application, you will often want to do a little preparation before navigation
  107. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  108. // Get the new view controller using [segue destinationViewController].
  109. // Pass the selected object to the new view controller.
  110. }
  111. */
  112. @end