此文学习来源为:http://study.163.com/course/introduction/1002858003.htm

此工程文件实现功能:

 1、警告对话框和等待提示器的概念

2、警告对话框和等待提示器的属性

3、警告对话框和等待提示器的使用

===========================ViewController.h脚本==============================  

@interface ViewController : UIViewController <UIAlertViewDelegate>

{

//定义一个警告对话框视图对象

UIAlertView* _alertView;

//等待提示对象

//当下载或加载比较大的文件时,可以显示此控件,处于提示等待状态

UIActivityIndicatorView* _activityIndicatorView;

}

@property (retain,nonatomic) UIAlertView* alertView;

@property (retain,nonatomic) UIActivityIndicatorView * activityIndicatorView;

@end

===========================ViewController.m脚本==============================

@interface ViewController ()

@end

@implementation ViewController

//属性和成员变量的同步

@synthesize alertView = _alertView;

@synthesize activityIndicatorView = _activityIndicatorView;

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

for (int i = 0; i < 2; i++) {

UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

btn.frame = CGRectMake(100, 100 + 100 * i, 100, 40);

if (i == 0) {

[btn setTitle:@"警告对话框" forState:UIControlStateNormal];

}

else if (i == 1)

{

[btn setTitle:@"等待指示器" forState:UIControlStateNormal];

}

btn.tag = 101 + i;

[btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:btn];

}

}

- (void) pressBtn:(UIButton*) btn

{

//警告对话框

if (btn.tag == 101) {

//创建警告对话框

//P1:对话框标题

//P2:提示信息

//P3:处理按钮事件的代理对象

//P4:取消按钮的文字

//P5:其他按钮文字

//P6....:添加其他按钮

//PLast:表示按钮添加结束

//两个按钮横着排,多个竖着排

_alertView = [[UIAlertView alloc] initWithTitle:@"警告"

message:@"你的手机电量过低,即将关机,请保存好数据"

delegate:self

cancelButtonTitle:@"取消"   //取消按钮永远放最后

otherButtonTitles:@"OK",@"11",@"22", nil];

//显示对话框

[_alertView show];

}

//创建等待提示器

else if (btn.tag == 102)

{

//宽度和高度不可变更

_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 300, 80, 80)];

//设定提示的风格:小灰,小白,大白

_activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;//UIActivityIndicatorViewStyleWhite;//UIActivityIndicatorViewStyleGray;

self.view.backgroundColor = [UIColor blackColor];

[self.view addSubview:_activityIndicatorView];

//启动动画并显示

[_activityIndicatorView startAnimating];

//停止等待动画并隐藏

//[_activityIndicatorView stopAnimating];

}

}

//当点击对话框的按钮时,调用此函数

//P1:对话框对象本身

//P2:按钮的索引

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

NSLog(@"index = %ld\n",buttonIndex);

}

//对话框即将消失,此函数被调用

- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

{

NSLog(@"即将消失");

}

//对话框已经消失,此函数被调用

- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

{

NSLog(@"对话框已经消失");

}

程序运行结果:

按钮

警告对话框(2个按钮:横排)

警告对话框(4个按钮:竖排)

等待指示器:(大白风格)

学习总结:

  • 重点:警告对话框和等待提示器的概念
  • 难点:警告对话框和等待提示器的用法

源码链接地址:https://pan.baidu.com/s/1yrOLXZZeu9MiOWtMq5-EGA  密码:7t1l

IOS开发之XCode学习014:警告对话框和等待提示器的更多相关文章

  1. IOS开发之XCode学习009:UIViewController使用

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 通过点击屏幕事件,调用ViewController ...

  2. IOS开发之XCode学习008:UIViewController基础

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 红色框选部分用A代替,AppDelegate类在程序框架启动时,如果在i ...

  3. IOS开发之XCode学习011:UISwitch控件

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UIswitch控件,添加UIswitc ...

  4. IOS开发之XCode学习007:UIWindow对象

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm #import "AppDelegate.h" @i ...

  5. IOS开发之XCode学习012:Slider和ProgressView

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UISlider和UIProgressV ...

  6. IOS开发之XCode学习010:定时器和视图对象

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.通过点击"启动定时器"按钮 ...

  7. IOS开发之XCode学习013:步进器和分栏控件

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UIStepper和UISegmente ...

  8. iOS开发之Xcode常用调试技巧总结

    转载自:iOS开发之Xcode常用调试技巧总结 最近在面试,面试过程中问到了一些Xcode常用的调试技巧问题.平常开发过程中用的还挺顺手的,但你要突然让我说,确实一脸懵逼.Debug的技巧很多,比如最 ...

  9. iOS开发之XCode设置--消除AFN的警告

    本篇是直接拷贝别人的博文,地址:http://blog.csdn.net/liyiyismile/article/details/50434844 在项目开发中导入第三方sdk后会提示很多这样的错误: ...

随机推荐

  1. Linux基础五

    Yum软件包管理 yum:基于rpm包构建的软件更新机制 自动解决软件包依赖关系 所有软件包由集中的yum软件仓库提供. [root@hydra桌面]#ls /misc/cd/repodata/ (r ...

  2. Android的ListView异步加载图片时,错位、重复、闪烁问题的分析及解决方法

    Android ListView异步加载图片错位.重复.闪烁分析以及解决方案,具体问题分析以及解决方案请看下文. 我们在使用ListView异步加载图片的时候,在快速滑动或者网络不好的情况下,会出现图 ...

  3. FMECA分析

    FMECA是针对产品所有可能的故障,并根据对故障模式的分析,确定每种故障模式对产品工作的影响,找出单点故障,并按故障模式的严重度及其发生概率确定其危害性.所谓单点故障指的是引起产品故障的,且没有冗余或 ...

  4. BT656跟BT1120和BT709有什么区别

    601是SDTV的数据结构 656是SDTV的interface709是HDTV的数据结构 1120是HDTV的interface从数据结构上 都是Y Cb Cr只是SDTV用4:2:2   HDTV ...

  5. grub2与grub区别

    关于版本: GRUB2 使之版本号为1.98之后的grub:GRUB legacy(版本为0.97)是指GRUB,而非GRUB2,grub是指 grub1.97 和以前的,grub 2 指的是 gru ...

  6. linux命令--ldconfig和ldd用法

    一.ldconfig ldconfig是一个动态链接库管理命令,为了让动态链接库为系统所共享,还需运行动态链接库的管理命令--ldconfig. ldconfig 命令的用途,主要是在默认搜寻目录(/ ...

  7. php出现Can't use function return value in write context

    <?php if(session('uid')){ }else{ } ?> 在用empty判断值为空的时候,报了这个Can't use function return value in w ...

  8. dojo实现省份地市级联报错(一)

  9. Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field

    1 错误描述 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.s ...

  10. Java获取某年某周的第一天

    Java获取某年某周的第一天 1.设计源码 FirstDayOfWeek.java: /** * @Title:FirstDayOfWeek.java * @Package:com.you.freem ...