alertView中的属性和方法的讲解
来源:互联网 发布:和女生网络聊天技巧 编辑:程序博客网 时间:2024/06/11 06:09
//
// ViewController.m
// alertView
//
// Created by 朱敏 on 15/7/14.
// Copyright © 2015年 helinyu. All rights reserved.
//
#import "ViewController.h"
@interface ViewController () <UIAlertViewDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"标题"message:@"message"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"其他",nil];
alert.delegate =self;
NSString * abutton = [alertbuttonTitleAtIndex:1];//获取button的索引名字,eg:索引1为 “其他”
NSLog(@"abutton is : %@",abutton);
NSLog(@"cancancelButtonIndex:%ld",alert.cancelButtonIndex);//获取取消按钮的索引,默认为0设置将会改变
NSInteger * number = [alertaddButtonWithTitle:@"选择"];//增加一个按钮,返回的是按钮的索引
NSLog(@"number is : %ld",number);
NSLog(@"numberOfButtons is :%ld",alert.numberOfButtons);//按钮的数目
NSLog(@"firstOtherButtonIndex is :%ld",alert.firstOtherButtonIndex);
//显示其他按钮中的第一个下标
NSLog(@"alert.visible is :%d",alert.visible);
// alert.visible = NO;
// - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
[alert dismissWithClickedButtonIndex:1animated:YES];//这个方法好像没有起到作用
//解除所以指定的按钮,当点击的时候,也就是不起到作用
// Alert view style - defaults to UIAlertViewStyleDefault
// @property(nonatomic,assign) UIAlertViewStyle alertViewStyle NS_AVAILABLE_IOS(5_0);
// alert.alertViewStyle = UIAlertViewStyleDefault; //默认的,没有UItextfield
// alert.alertViewStyle = UIAlertViewStyleSecureTextInput;//密码的输入UitextField
// alert.alertViewStyle = UIAlertViewStylePlainTextInput;//设置一个空白的UITextField
alert.alertViewStyle =UIAlertViewStyleLoginAndPasswordInput;//用户和密码
// Retrieve a text field at an index
// The field at index 0 will be the first text field (the single field or the login field), the field at index 1 will be the password field. */
// - (nullable UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);
UITextField * atextfield0 = [alerttextFieldAtIndex:0];
UITextField * atextfield1 = [alerttextFieldAtIndex:1];
// UITextField * atextfield2 = [alert textFieldAtIndex:2];
// UITextField * atextfield3 = [alert textFieldAtIndex:3];
//也就是alertView最多也就是只能够增加两个UITextField
//增加的时候记得设置alertView的样式
UILabel * label =[[UILabelalloc]initWithFrame:CGRectMake(0,0,50,20)];
label.text =@"hello";
[alert addSubview:label];
[alert show];
}
#pragma mark <UIAlertViewDelegate>
//监听点击按钮事件
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndexNS_DEPRECATED_IOS(2_0,9_0)
{
NSLog(@"buttonIndex is : %ld",(long)buttonIndex);//监听点击当时的代理方法,
//点击之后按钮将会消除,就会被消除按钮监听
if(buttonIndex == alertView.cancelButtonIndex)
{
NSLog(@"cancelButtonIndex : %ld",(long)alertView.cancelButtonIndex);
}else{
NSLog(@"no cancelButtonIndex : %ld",(long)buttonIndex);
}
}
//可以根据打印的结果
//2015-07-14 09:37:46.163 alertView[23448:742979] buttonIndex is : 1
//2015-07-14 09:37:46.163 alertView[23448:742979] willDismissWithButtonIndex : 1
//2015-07-14 09:37:46.581 alertView[23448:742979] didDismissWithButtonIndex: 1
//事件为:点击alertView之外的地方,alertView将会显示
- (void)alertViewCancel:(UIAlertView *)alertViewNS_DEPRECATED_IOS(2_0,9_0)
{
//这个方法应该是处理程序异常关闭的这个alertView之后调用的方法。????
NSLog(@"alertViewCancel");
}
//alertView将要显示和显示后的监听方法
- (void)willPresentAlertView:(UIAlertView *)alertViewNS_DEPRECATED_IOS(2_0,9_0)
{
NSLog(@"willPresentAlertView");
}// before animation and showing view
- (void)didPresentAlertView:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0,9_0)
{
NSLog(@"didPresentAlertView");
}// after animation
//这下面两个方法是监听上面的dismissWithClickedButtonIndex:方法,
//同时监听点击之后,按钮将会消除,所以也会监听点击之后的操作
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0,9_0)
{
NSLog(@"willDismissWithButtonIndex : %ld",buttonIndex);
}// before animation and hiding view
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0,9_0)
{
NSLog(@"didDismissWithButtonIndex: %ld",buttonIndex);
}// after animation
// Called after edits in any of the default fields added by the style
//在任何默认字段添加的样式中调用后调用
//其他中的按钮第一个alertView应该启动
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0,9_0)
{
NSLog(@"alertViewShouldEnableFirstOtherButton");
returnYES;
}
//https://github.com/wimagguc/ios-custom-alertview自定义alertView
//其中UIActionSheet和UIalertView中的方法原理dou都是一个样。
@end
- alertView中的属性和方法的讲解
- Actionsheet和AlertView的使用
- alertview和alertviewcontroller的关系
- ActionSheet和AlertView的封装
- javascript Event方法和属性讲解
- 关于自定义AlertView背景的方法收集
- 关于自定义AlertView背景的方法收集
- 关于自定义AlertView背景的方法收集
- 关于自定义AlertView背景的方法收集
- 关于自定义AlertView背景的方法收集
- Android开发自动生成的AndroidManifest.xml中的allowBackup属性的含义和危险性实例讲解
- XMLHttpRequest 中的属性和方法
- IOS中的通知--操作表ActionSheet和警报AlertView
- IOS中的通知--操作表ActionSheet和警报AlertView
- 实例讲解在JSP开发中的对象和范围属性
- 当control中有alertview和key windown同时出现的时候加载keywindown中的视图不显示
- js中的子类继承父类的方法和属性
- 对象的创建,访问类中的属性和方法
- MFC技术内幕系列之(五)---MFC文档序列化内幕
- Javascript arguments对象
- 支付宝国际支付 对接
- nginx配置中rewrite中变量判断conditon
- RROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
- alertView中的属性和方法的讲解
- 【Java】检查二叉树是否平衡。
- Android主activity向自定义view传递参数
- SAP主数据管理
- EGOCache如何检测缓存时间过期
- poj 3667 Hotel (线段树 + 合并操作)
- 悟空学Linux专栏----第33篇
- android使用ViewPager实现底部菜单栏和左右滑动效果,加载多个Activity
- 悟空学Linux专栏----第34篇