UIAlertView 开发笔记


  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. - (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  

http://blog.csdn.net/banyingli/article/details/6167592


/AlertView 添加textfield/

    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:titlStr message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

    alertView.alertViewStyleUIAlertViewStylePlainTextInput;

    [[alertView textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];

    [[alertView textFieldAtIndex:0] becomeFirstResponder];

    [[alertView textFieldAtIndex:0]setDelegate:self];

    [[alertView textFieldAtIndex:0]setTextAlignment:NSTextAlignmentCenter] ;

    [alertView show];

/*

typedef NS_ENUM(NSInteger, UIAlertViewStyle) {

    UIAlertViewStyleDefault = 0,

    UIAlertViewStyleSecureTextInput, //密码

    UIAlertViewStylePlainTextInput,//一个textfield

    UIAlertViewStyleLoginAndPasswordInput //登录 and 密码

};

*/



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值