iPhone开发UIAlertView属性及使用方法

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值