一回窘、UIAlertView
UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];
[alert show];
二、UIAlertView的代理方法
@interface ViewController : UIViewController<UIAlertViewDelegate>
@end
1底哥、 //根據(jù)被點擊按鈕的索引處理點擊事件
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ NSLog(@"clickButtonAtIndex:%d",buttonIndex); }
2莽囤、 //AlertView已經(jīng)消失時執(zhí)行的事件
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{ NSLog(@"didDismissWithButtonIndex"); }
3谬擦、//ALertView即將消失時的事件
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{ NSLog(@"willDismissWithButtonIndex"); }
4、//AlertView的取消按鈕的事件
-(void)alertViewCancel:(UIAlertView *)alertView
{ NSLog(@"alertViewCancel"); }
5朽缎、//AlertView已經(jīng)顯示時的事件
-(void)didPresentAlertView:(UIAlertView *)alertView
{ NSLog(@"didPresentAlertView"); }
6怯屉、//AlertView即將顯示時
-(void)willPresentAlertView:(UIAlertView *)alertView
{ NSLog(@"willPresentAlertView"); }
三、UIActionSheet
UIActionSheet * sheet=[[UIActionSheet alloc]initWithTitle:@"您要撥打哪個電話饵沧?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"0731-89786224" otherButtonTitles:@"400-1808-178", nil];
[sheet showInView:self.view];
四锨络、UIActionSheet代理方法
1、//根據(jù)被點擊按鈕的索引處理點擊事件
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{ }
2狼牺、//ActionSheet的取消按鈕的事件
- (void)actionSheetCancel:(UIActionSheet *)actionSheet;
3羡儿、//ActionSheet即將顯示時
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet; // before animation and showing view
4、//ActionSheet已經(jīng)顯示時的事件
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet; // after animation
5是钥、//ActionSheet即將消失時的事件
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex; // before animation and hiding view
6掠归、 //ActionSheet已經(jīng)消失時執(zhí)行的事件
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation
五、二者的區(qū)別
UIActionSheet用于迫使用戶在兩個或更多的選項之間進行選擇的模式視圖悄泥。操作表是從屏幕底部彈出虏冻,顯示一系列按鈕供用戶選擇,用戶只有單擊一個按鈕后才能繼續(xù)使用應用程序弹囚。(可以理解為桌面應用系統(tǒng)的右鍵菜單的功能)
UIAlertView警告默認是以藍色圓角矩形形式顯示在屏幕中央厨相,警告框可顯示一個或多個按鈕。