#import "ViewController.h"spa
//遵照代理.net
@interface ViewController ()<UIAlertViewDelegate>代理
@end 繼承
@implementationViewController索引
- (void)viewDidLoad {get
[super viewDidLoad];it
/**io
初始化UIAlertViewclass
*/import
UIAlertView *alertview = [[UIAlertView alloc]initWithTitle:@"節日祝福" message:@"新年好,恭喜發財" delegate:self cancelButtonTitle:@"其餘" otherButtonTitles:@"肯定", nil];
//設置標題信息
alertview.title = @"UIAlertView";
alertview.message = @"UIAlertViewMessage";
//當一個視圖有多個UIAlertView 能夠用 tag 來區分,這個屬性繼承自 UIview
alertview.tag = 0;
//只讀屬性,看alertview是否可見
NSLog(@"%d",alertview.visible);
//經過給定標題添加按鈕
[alertview addButtonWithTitle:@"我是一個新加的按鈕"];
//按鈕總數
NSLog(@"buttonNum:%zd",alertview.numberOfButtons);
//獲取指定索引的按鈕標題
NSLog(@"buttonIndex1:%zd",[alertview buttonTitleAtIndex:1]);
NSLog(@"buttonIndex2:%zd",[alertview buttonTitleAtIndex:2]);
//獲取取消按鈕的索引
NSLog(@"cencelButtonIndex:%zd",[alertview cancelButtonIndex]);
//獲取第一個其餘按鈕的索引
NSLog(@"firstOtherButtonIndex:%zd",[alertview firstOtherButtonIndex]);
//顯示alertview
//注意UIAlertView調用show顯示出來的時候,系統會自動強引用它,不會被釋放
[alertview show];
}
#pragma mark----------------------------------------UIAlertView代理方法
//根據被點擊按鈕的索引會調用此方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"clickButtonAtIndex:%zd",buttonIndex);
}
//AlertView已經消失時會調用此方法
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"didDismissWithButtonIndex");
}
//ALertView即將消失時會調用此方法
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"willDismissWithButtonIndex");
}
//AlertView的取消按鈕會調用此方法
-(void)alertViewCancel:(UIAlertView *)alertView
{
NSLog(@"alertViewCancel");
}
//AlertView已經顯示時會調用此方法
-(void)didPresentAlertView:(UIAlertView *)alertView
{
NSLog(@"didPresentAlertView");
}
//AlertView即將顯示時會調用此方法
-(void)willPresentAlertView:(UIAlertView *)alertView
{
NSLog(@"willPresentAlertView");
}
@end