您的位置:首页 > 产品设计 > UI/UE

浅谈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");

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: