iOS学习笔记—— UIAlertView 和 UIActionSheet 的使用

       一、UIAlertView类似Windows中的对话框,出现在屏幕的中央,可有两个至多个选项供用户选择。遵守UIAlertViewDelegate 协议。

       iOS学习笔记—— UIAlertView 和 UIActionSheet 的使用_第1张图片

       使用方法:

       1.声明:

    UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"AlertView"
                              message:@"Alert text goes here"
                              delegate:self
                              cancelButtonTitle:@"No"
                              otherButtonTitles:@"Yes", @"Cancel", nil];
    [alertView show];

       2.消息响应函数:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"buttonIndex = %i",buttonIndex);   
}

       二、UIActionSheet 与 UIAlertView 类似,但它出现在屏幕下方。遵守UIActionSheetDelegate 协议。

        iOS学习笔记—— UIAlertView 和 UIActionSheet 的使用_第2张图片

       使用方法:

       1.声明:

UIActionSheet *actionSheet = [[UIActionSheet alloc]
							 initWithTitle:@“ActionSheet”
							 delegate:self
							 cancelButtonTitle:@"取消"
							 destructiveButtonTitle:@"选项一"
							 otherButtonTitles:@"选项二",@"选项三",nil];
	
actionSheet.actionSheetStyle =  UIActionSheetStyleAutomatic;
[actionSheet showInView:self.view];

       2.消息响应函数:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"buttonIndex = %i",buttonIndex);
}



你可能感兴趣的:(ios)