浅谈UIAlertView
2015-09-05 13:39
645 查看
一、定义
View *alertView = [[UIAlertView alloc]
initWithTitle:@"提示" message:@"您选择的当前城市",delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
如果需要添加多个按钮,可以在
otherButtonTitles 后面 直接添加
二、事件响应
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
//事件响应,根据参数buttonIndex的值,来确定是那样一个按钮被点击,进而对不同的按钮事件做不同的处理
三、其它
也可以不添加任何按钮,只显示信息,设置一个定时器,过一定时间自动消失
UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"请等待"
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[alert show];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(dealDismissAlert:) userInfo:@{@"alert":alert} repeats:NO];
- (void)dealDismissAlert:(NSTimer *)timer
{
UIAlertView *alert = timer.userInfo[@"alert"];
[alert dismissWithClickedButtonIndex:0
animated:YES];
}
//只读属性,看AlertView是否可见
NSLog(@"%d",alert.visible);
//通过给定标题添加按钮
[alert addButtonWithTitle:@"addButton"];
//按钮总数
NSLog(@"numberOfButtons:%d",alert.numberOfButtons);
//获取指定索引的按钮的标题
NSLog(@"buttonTitleAtIndex:%@",[alert button
ae5a
TitleAtIndex:2]);
//获得取消按钮的索引
NSLog(@"cancelButtonIndex:%d",alert.cancelButtonIndex);
//获得第一个其他按钮的索引
NSLog(@"firstOtherButtonIndex:%d",alert.firstOtherButtonIndex);
//AlertView已经消失时
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"didDismissWithButtonIndex");
}
//AlertView即将消失时
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"willDismissWithButtonIndex");
}
//当用户按下HOME键的时候,回调此方法,用户点击Cancel按钮的时候不会回调此方法
- (void)alertViewCancel:(UIAlertView *)alertView;
//AlertView已经显示时
- (void)didPresentAlertView:(UIAlertView *)alertView {
NSLog(@"didPresentAlertView");
}
//AlertView即将显示时
- (void)willPresentAlertView:(UIAlertView *)alertView {
NSLog(@"willPresentAlertView");
}
View *alertView = [[UIAlertView alloc]
initWithTitle:@"提示" message:@"您选择的当前城市",delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
如果需要添加多个按钮,可以在
otherButtonTitles 后面 直接添加
二、事件响应
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
//事件响应,根据参数buttonIndex的值,来确定是那样一个按钮被点击,进而对不同的按钮事件做不同的处理
三、其它
也可以不添加任何按钮,只显示信息,设置一个定时器,过一定时间自动消失
UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"请等待"
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[alert show];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(dealDismissAlert:) userInfo:@{@"alert":alert} repeats:NO];
- (void)dealDismissAlert:(NSTimer *)timer
{
UIAlertView *alert = timer.userInfo[@"alert"];
[alert dismissWithClickedButtonIndex:0
animated:YES];
}
//只读属性,看AlertView是否可见
NSLog(@"%d",alert.visible);
//通过给定标题添加按钮
[alert addButtonWithTitle:@"addButton"];
//按钮总数
NSLog(@"numberOfButtons:%d",alert.numberOfButtons);
//获取指定索引的按钮的标题
NSLog(@"buttonTitleAtIndex:%@",[alert button
ae5a
TitleAtIndex:2]);
//获得取消按钮的索引
NSLog(@"cancelButtonIndex:%d",alert.cancelButtonIndex);
//获得第一个其他按钮的索引
NSLog(@"firstOtherButtonIndex:%d",alert.firstOtherButtonIndex);
//AlertView已经消失时
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"didDismissWithButtonIndex");
}
//AlertView即将消失时
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"willDismissWithButtonIndex");
}
//当用户按下HOME键的时候,回调此方法,用户点击Cancel按钮的时候不会回调此方法
- (void)alertViewCancel:(UIAlertView *)alertView;
//AlertView已经显示时
- (void)didPresentAlertView:(UIAlertView *)alertView {
NSLog(@"didPresentAlertView");
}
//AlertView即将显示时
- (void)willPresentAlertView:(UIAlertView *)alertView {
NSLog(@"willPresentAlertView");
}
相关文章推荐
- javaSE基础编程——GUI窗体设计之记事本(使用监听器)
- VIM编辑器:使用cscope老是出现一些E259: no matches found for csope query 问题;
- javaSE基础编程——GUI窗体
- EasyUi 合并单元格占列显示
- UE4的delegate
- 'sessionFactory' or 'hibernateTemplate' is required
- mac下使用QuickTime录屏及上传youku注意事项
- easyUI的高级查询
- Unique Paths
- IOS_UI_传值
- IOS_TextField,UIButton
- IOS_UI_Label
- mysql 插入中文时出现ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern ame' at row 1
- Android UI设计:ViewFlipper使图片循环滑动
- iOS 关于UICollectionView的cell重用问题
- GCC内建函数 __builtin_return_address实现
- hdu 1121 Complete the Sequence(插值差分)
- 关于divide and conquer的两道Leetcode
- HDU1711 Number Sequence(KMP模版题)
- parseInt和valueOf