[iPhone开发之控件的使用]UIAlertView的各种属性、方法及代理的使用

[c-sharp]  view plain copy
  1. #import "AlertViewTestViewController.h"  
  2. @implementation AlertViewTestViewController  
  3.   
  4. /* 
  5.  Tasks 
  6.   
  7.  Creating Alert Views 
  8.     – initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:   
  9.  Setting Properties 
  10.     delegate  property   
  11.     title  property   
  12.     message  property   
  13.     visible  property   
  14.  Configuring Buttons 
  15.     – addButtonWithTitle:   
  16.     numberOfButtons  property   
  17.     – buttonTitleAtIndex:   
  18.     cancelButtonIndex  property   
  19.     firstOtherButtonIndex  property   
  20.  Displaying 
  21.     – show   
  22.  Dismissing 
  23.     – dismissWithClickedButtonIndex:animated:  无例 
  24. */  
  25.   
  26. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  27. - (void)viewDidLoad {  
  28.     //初始化AlertView  
  29.     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"AlertViewTest"   
  30.                             message:@"message"   
  31.                             delegate:self   
  32.                             cancelButtonTitle:@"Cancel"   
  33.                             otherButtonTitles:@"OtherBtn",nil];  
  34.     //设置标题与信息,通常在使用frame初始化AlertView时使用  
  35.     alert.title = @"AlertViewTitle";  
  36.     alert.message = @"AlertViewMessage";  
  37.       
  38.     //这个属性继承自UIView,当一个视图中有多个AlertView时,可以用这个属性来区分  
  39.     alert.tag = 0;  
  40.       
  41.     //只读属性,看AlertView是否可见  
  42.     NSLog(@"%d",alert.visible);  
  43.       
  44.     //通过给定标题添加按钮  
  45.     [alert addButtonWithTitle:@"addButton"];  
  46.       
  47.     //按钮总数  
  48.     NSLog(@"numberOfButtons:%d",alert.numberOfButtons);  
  49.       
  50.     //获取指定索引的按钮的标题  
  51.     NSLog(@"buttonTitleAtIndex:%@",[alert buttonTitleAtIndex:2]);  
  52.       
  53.     //获得取消按钮的索引  
  54.     NSLog(@"cancelButtonIndex:%d",alert.cancelButtonIndex);  
  55.       
  56.     //获得第一个其他按钮的索引  
  57.     NSLog(@"firstOtherButtonIndex:%d",alert.firstOtherButtonIndex);  
  58.       
  59.     //显示AlertView  
  60.     [alert show];  
  61.       
  62.     [alert release];  
  63.     [super viewDidLoad];  
  64. }  
  65.   
  66. /* 
  67. // Override to allow orientations other than the default portrait orientation. 
  68. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  69.     // Return YES for supported orientations 
  70.     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
  71. } 
  72. */  
  73. - (void)didReceiveMemoryWarning {  
  74.     // Releases the view if it doesn't have a superview.  
  75.     [super didReceiveMemoryWarning];  
  76.       
  77.     // Release any cached data, images, etc that aren't in use.  
  78. }  
  79. - (void)viewDidUnload {  
  80.     // Release any retained subviews of the main view.  
  81.     // e.g. self.myOutlet = nil;  
  82. }  
  83.   
  84. - (void)dealloc {  
  85.     [super dealloc];  
  86. }  
  87. #pragma mark  -- UIAlertViewDelegate --  
  88. //根据被点击按钮的索引处理点击事件  
  89. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {  
  90.     NSLog(@"clickedButtonAtIndex:%d",buttonIndex);  
  91. }  
  92. //AlertView已经消失时  
  93. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {  
  94.     NSLog(@"didDismissWithButtonIndex");  
  95. }  
  96. //AlertView即将消失时  
  97. - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {  
  98.     NSLog(@"willDismissWithButtonIndex");  
  99. }  
  100.   
  101. - (void)alertViewCancel:(UIAlertView *)alertView {  
  102.     NSLog(@"alertViewCancel");  
  103. }  
  104. //AlertView已经显示时  
  105. - (void)didPresentAlertView:(UIAlertView *)alertView {  
  106.     NSLog(@"didPresentAlertView");  
  107. }  
  108. //AlertView即将显示时  
  109. - (void)willPresentAlertView:(UIAlertView *)alertView {  
  110.     NSLog(@"willPresentAlertView");  
  111. }  
  112. @end  


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值