iOS之UIAlertView的使用

本文详细介绍了UIAlertView的基本用法,包括创建简单的警告框、设置不同样式、实现账号密码输入以及如何通过代理方法来响应用户操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIAlertView:

 

1.普通使用:

    //普通的alert

    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];

    [av show];

 

2.UIAlertView还可以设置其样式:

如果可以输入账号与密码的样式:

    //普通的alert

    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];

    [av setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];//设置样式:明文与暗文

    [av show];

 

3.判断用户点击了alert的哪个按钮的协议:

 

//协议:alertView

//判断用户点击了alert的那个按钮

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

{

    if(buttonIndex == 0)

    {

        NSLog(@"you click no");

    }

    else

    {

        NSLog(@"you click yes");

    }

}

 

4.   常用方法总结:

  1. //根据被点击按钮的索引处理点击事件  
  2. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
  3. {  
  4.     NSLog(@"clickButtonAtIndex:%d",buttonIndex);  
  5. }  
  6.   
  7. //AlertView已经消失时执行的事件  
  8. -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex  
  9. {  
  10.     NSLog(@"didDismissWithButtonIndex");  
  11. }  
  12.   
  13. //ALertView即将消失时的事件  
  14. -(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex  
  15. {  
  16.     NSLog(@"willDismissWithButtonIndex");  
  17. }  
  18.   
  19. //AlertView的取消按钮的事件  
  20. -(void)alertViewCancel:(UIAlertView *)alertView  
  21. {  
  22.     NSLog(@"alertViewCancel");  
  23. }  
  24.   
  25. //AlertView已经显示时的事件  
  26. -(void)didPresentAlertView:(UIAlertView *)alertView  
  27. {  
  28.     NSLog(@"didPresentAlertView");  
  29. }  
  30.   
  31. //AlertView即将显示时  
  32. -(void)willPresentAlertView:(UIAlertView *)alertView  
  33. {  
  34.     NSLog(@"willPresentAlertView");  
posted on 2016-03-23 22:57 bky2016 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/calence/p/5313555.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值