zoukankan      html  css  js  c++  java
  • UIWebView显示网页

    #import "ViewController.h"

    #import "MBProgressHUD.h"

    @interface ViewController ()<UIWebViewDelegate>

    {

        

        MBProgressHUD *HUD;

        

    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        //    网页视图

        UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.frame];

        webView.delegate = self;

        [self.view addSubview:webView];

        

        

        /*

         百度地图有关的网址http://api.map.baidu.com/marker?location=39.916979519873,116.41004950566&title=我的位置&content=百度

         奎科大厦&output=html

         

         http://map.baidu.com/mobile/webapp/index/index/?itj=45&wtj=wi

         

         NSString *string = [[NSBundle mainBundle]pathForResource:@"hhh.pdf" ofType:nil];

         

         //   - (void)loadRequest:(NSURLRequest *)request; 加载本地文件 或 网页

         

         //     网页视图加载的请求

         NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:string]];

         */

        //    网页视图需要一个加载的请求 加载的内容放在请求里面

        

    #pragma mark-----------加载网页

        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com"]];

        

        [webView loadRequest:request];

    //    等待视图初始化

        HUD = [[MBProgressHUD alloc]initWithView:self.view];

        

        [self.view addSubview:HUD];

    }

    //开始加载

    - (void)webViewDidStartLoad:(UIWebView *)webView{

    //    设置等待视图的提示文字

        HUD.labelText = @"正在拼命加载...";

    //    显示等待视图

        [HUD show:YES];

    }

    //加载完毕

    - (void)webViewDidFinishLoad:(UIWebView *)webView{

    //    隐藏等待试图

            [HUD hide:YES];

    }

    //加载失败

    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{

        

        HUD.labelText = [NSString stringWithFormat:@"error:网络连接失败"];

        //    NSLog(@"%@",error);

        //    显示等待视图

        [HUD show:YES];

        //    3秒后隐藏等待试图

        [HUD hide:YES afterDelay:3];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    主机与虚拟机通信:以主机VS2010连接虚拟机MySql为例
    Json与类对象转换
    VS附加到进程调试的方法及应用场景
    地图API使用文档-以腾讯地图为例
    JS使用ActiveXObject读取数据库代码示例(只支持IE)
    css文件内引用外部资源文件的相对路径
    ::after,::before使用
    高德地图API应用
    LogNet4学习笔记
    MvcPager分页控件的使用
  • 原文地址:https://www.cnblogs.com/liumu/p/5308932.html
Copyright © 2011-2022 走看看