UIWebView加载Loading...

2024-04-18 11:48
文章标签 加载 loading uiwebview

本文主要是介绍UIWebView加载Loading...,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

ViewController.h文件



#import <UIKit/UIKit.h>


@interface ViewController :UIViewController<UIWebViewDelegate>//加载声明UIWebviewDelegate协议  

{

   UIWebView *webView;

   UIActivityIndicatorView *activityIndicator;

    

}




ViewController.m文件

//加载网页

- (void)viewDidLoad

{

    [superviewDidLoad];

    webView = [[UIWebViewalloc] initWithFrame:CGRectMake(0,0, 320,480)];

    [webViewsetDelegate:self];

    NSURLRequest *request =[NSURLRequestrequestWithURL:[NSURLURLWithString:@"http://www.zqksk.com/ios/xzqcf/index.html"]];

    [self.viewaddSubview: webView];

    [webViewloadRequest:request];

    

   }

/// //开始加载数据   

- (void) webViewDidStartLoad:(UIWebView *)webView

{

    //创建UIActivityIndicatorView背底半透明View     

   UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(0,0, 320, 480)];  

    [viewsetTag:108];  

    [view setBackgroundColor:[UIColorblackColor]];  

    [viewsetAlpha:0.5];  

    [self.viewaddSubview:view];  

    

    activityIndicator = [[UIActivityIndicatorViewalloc] initWithFrame:CGRectMake(0.0f,0.0f, 32.0f, 32.0f)];  

    [activityIndicatorsetCenter:view.center];  

    [activityIndicatorsetActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];  

    [view addSubview:activityIndicator];  


    [activityIndicatorstartAnimating];

    NSLog(@"webViewDidStartLoad");

}

/////数据加载完  

- (void) webViewDidFinishLoad:(UIWebView *)webView

{

    [activityIndicatorstopAnimating];

   UIView *view = (UIView*)[self.viewviewWithTag:108];

    [view removeFromSuperview];

    NSLog(@"webViewDidFinishLoad");


}

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

{

    [activityIndicatorstopAnimating];

   UIView *view = (UIView*)[self.viewviewWithTag:108];

    [view removeFromSuperview];

    NSLog(@"didFailLoadWithError:%@", error);

}


自己使用以下方式:
//加载网页动画  

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

    

   if (myAlert==nil){

        myAlert = [[UIAlertViewalloc] initWithTitle:nil

                                            message: @"正在玩命加载当中..."

                                           delegate: self

                                  cancelButtonTitle: nil

                                  otherButtonTitles: nil];

        

        UIActivityIndicatorView *activityView = [[UIActivityIndicatorViewalloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];//加载时指示器的颜色

        activityView.frame =CGRectMake(120.f,48.0f, 37.0f,37.0f);//设置对象的位置,大小是固定不变的。WhiteLarge为37 * 37,White为20 * 20

        activityView.color = [UIColor redColor];//指示器的颜色

        [myAlertaddSubview:activityView];//将对像加入到VIEW

        [activityViewrelease];要记得将对象release

        [activityViewstartAnimating];//开启动画(指示器)

        [myAlertshow];

    }

    

    _reloading = YES;

}

////数据加载完 

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

     [myAlertdismissWithClickedButtonIndex:0animated:YES];

    

    _reloading = NO;

    [_refreshHeaderViewegoRefreshScrollViewDataSourceDidFinishedLoading:self.uiWebView.scrollView];

}

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

    NSLog(@"load page error:%@", [errordescription]);

    _reloading = NO;

[_refreshHeaderViewegoRefreshScrollViewDataSourceDidFinishedLoading:self.uiWebView.scrollView];

}

转:

http://justcoding.iteye.com/blog/1535070

http://lijinfengjava.iteye.com/blog/1508377

http://blog.sina.com.cn/s/blog_7fa6b06f010121mr.html




这篇关于UIWebView加载Loading...的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/914700

相关文章

【 html+css 绚丽Loading 】000046 三才归元阵

前言:哈喽,大家好,今天给大家分享html+css 绚丽Loading!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 📚一、效果📚二、信息💡1.简介:💡2.外观描述:💡3.使用方式:💡4.战斗方式:💡5.提升:💡6.传说: 📚三、源代码,上代码,可以直接复制使用🎥效果🗂️目录✍️

Flutter 进阶:绘制加载动画

绘制加载动画:由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类:LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态,而 LoadingPainter 则负责绘制动画。

使用WebP解决网站加载速度问题,这些细节你需要了解

说到网页的图片格式,大家最常想到的可能是JPEG、PNG,毕竟这些老牌格式陪伴我们这么多年。然而,近几年,有一个格式悄悄崭露头角,那就是WebP。很多人可能听说过,但到底它好在哪?你的网站或者项目是不是也应该用WebP呢?别着急,今天咱们就来好好聊聊WebP这个图片格式的前世今生,以及它值不值得你花时间去用。 为什么会有WebP? 你有没有遇到过这样的情况?网页加载特别慢,尤其是那

gazebo 已加载模型但无法显示

目录 写在前面的话问题一:robot_state_publisher 发布机器人信息失败报错一 Error: Error document empty.报错二 .xcaro 文件中有多行注释成功启动 问题二:通过 ros2 启动 gazebo 失败成功启动 问题三:gazebo 崩溃和无法显示模型问题四: 缺少 robot_description 等话题正确的输出 写在前面的话

JVM类的加载器及加载过程

类的加载器及加载过程 文章目录 类的加载器及加载过程类的加载过程加载:链接(验证、准备、解析):初始化: 类加载器的分类引导类加载器:BootstrapClassLoader 启动类加载器( C/C++实现,嵌套在JVM内部)自定义类加载器(所有派生于抽象类ClassLoader的类加载器)获取ClassLoader的途径 双亲委派机制(重点)判断两个Class对象是否为同一个类

Unity Adressables 使用说明(六)加载(Load) Addressable Assets

【概述】Load Addressable Assets Addressables类提供了加载 Addressable assets 的方法。你可以一次加载一个资源或批量加载资源。为了识别要加载的资源,你需要向加载方法传递一个键或键列表。键可以是以下对象之一: Address:包含你分配给资源的地址的字符串。Label:包含分配给一个或多个资源的标签的字符串。AssetReference Obj

Eclipse发布Maven项目到tomcat,无法加载到lib文件夹下的jar包

BMS 解决方法: 当我们发布web项目到tomcat时,访问地址时会报一个classnotfound的错误,但是eclipse中的项目中都已经添加了相应的类,有一种比较容易犯的错误是,你没有把额外所需的jar包加到tomcat中的lib文件夹中,在这里介绍一种在项目中直接添加jar包到lib目录下:  右键已创建的web项目——properties属性——点击Deployment Assem

jupyter在加载pkl文件时报错ModuleNotFoundError: No module named 'pandas.core.internals.managers'; '的解决方法

笔者当看到这个错误的时候一脸懵逼,在pycharm上正常运行的code 放在jupyter就不成了,于是就研究一翻。 一开始以为自己的pkl文件有问题,研究重点放在这里,最后发现不是。 然后取搜索pycharm和jupyter下的python的\Lib\site-packages\pandas\core\internals有什么不同 发现jupyter下没有pandas\core\intern

error while loading shared libraries: libnuma.so.1: cannot open shared object file:

腾讯云CentOS,安装Mysql时: 1.yum remove libnuma.so.1 2.yum install numactl.x86_64

【Visual Studio 报错】未加载 wntdll.pdb(一种可行的解决办法)

调试程序时,会出现下面这个报错 分析原因: 出现未加载 wntdll.pdb 报错大概率是你的指针使用错误 ,比如使用野指针、越界访问、或者堆区空间释放方式错误等。 这里以 堆区空间释放方式错误 为例子 1、堆区开辟的数组空间使用 delete 释放 // 堆区开辟的数组空间使用 delete 释放int* p = new int[10];delete p; 正