一:UIAlertView警告框 IOS 2 - IOS 9
UIAlertView*AlertView=[[UIAlertView alloc]initWithTitle:@"請(qǐng)給我們一個(gè)評(píng)價(jià)" message:@"我們很盡力的去做一個(gè)應(yīng)用掐暮,請(qǐng)給我們一個(gè)評(píng)價(jià)" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
[AlertView show];//展示出來(lái)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
觸摸屏幕調(diào)用這個(gè)函數(shù)
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
選擇按鍵后調(diào)用函數(shù)蝎抽。
NSLog(@"我們選擇了那一個(gè)按鍵%d",buttonIndex);
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
警告消失后調(diào)用函數(shù)。
NSLog(@"已經(jīng)消失路克,按鍵是哪一個(gè)");
}
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"即將消失樟结,按鍵是那一個(gè)");
}
-(void)alertViewCancel:(UIAlertView *)alertView
{
點(diǎn)擊取消鍵調(diào)用函數(shù)
NSLog(@"點(diǎn)取消按鍵");
}
二:UIActionSheet從下面彈出來(lái)的提示框,IOS 2 - IOS 8.3
遵從 UIActionSheetDelegate協(xié)議
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIActionSheet*ActionSheet=[[UIActionSheet alloc]initWithTitle:@"資源名" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"你猜" otherButtonTitles:@"你在猜", nil];
[ActionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"點(diǎn)擊了哪個(gè)");
}
三:UIAlertController,繼承自UIViewController,用以替代UIAlertView和UIActionSheet衷戈,IOS 8開始狭吼。
實(shí)例化方法為+ (instancetype)alertControllerWithTitle:(nullableNSString*)title message:(nullableNSString*)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
typedefNS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet =0,
UIAlertControllerStyleAlert
}NS_ENUM_AVAILABLE_IOS(8_0);對(duì)應(yīng)alert和action兩種樣式。
通過(guò)- (void)addAction:(UIAlertAction*)action;來(lái)添加按鈕項(xiàng)殖妇。
在項(xiàng)目中刁笙,可以創(chuàng)建一個(gè)alert管理類,來(lái)管理整個(gè)項(xiàng)目中的彈出框谦趣。