iOS开发 对话框UIActionSheet和UIAlertView用法
2012-04-06 15:58
281 查看
UIActionSheet和UIAlertView在iOS中,都是弹出一个对话框,用户必须点击上面的按钮后才能执行其他操作。
下图是UIActionSheet,对话框显示在底部:
下图是AlertView,显示在屏幕正中:
当按钮在两个以内时,按钮是水平显示的,当超过两个时,会垂直显示。
相当代码:
首先在viewController h头文件添加UIActionSheetDelegate,UIAlertViewDelegate协议,如下:
以下代码在ViewController.m文件中
打开ActionSheet对话框:
接收ActionSheet点击事件,以及打开AlertView对话框、接收AlertView点击事件:
下图是UIActionSheet,对话框显示在底部:
下图是AlertView,显示在屏幕正中:
当按钮在两个以内时,按钮是水平显示的,当超过两个时,会垂直显示。
相当代码:
首先在viewController h头文件添加UIActionSheetDelegate,UIAlertViewDelegate协议,如下:
1 2 | #import <UIKit/UIKit.h> @interface TESTViewController : UIViewController <UIActionSheetDelegate,UIAlertViewDelegate> |
打开ActionSheet对话框:
1 2 | UIActionSheet *sheet=[[UIActionSheet alloc] initWithTitle:@"你确定?" delegate:self cancelButtonTitle:@"不确定" destructiveButtonTitle:@"非常确定" otherButtonTitles: nil]; [sheet showInView:self.view]; |
1 23 | -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { //该方法由UIActionSheetDelegate协议定义,在点击ActionSheet的按钮后自动执行 NSString *string=[NSString stringWithFormat:@"你点击了 %@",[actionSheet buttonTitleAtIndex:buttonIndex]]; UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:string delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil]; [alert show]; } -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { //该方法由UIAlertViewDelegate协议定义,在点击AlertView按钮时自动执行,所以如果这里再用alertView来弹出提//示,就会死循环,不停的弹AlertView NSString * string=[NSString stringWithFormat:@"你点击了 %@",[alertView buttonTitleAtIndex:buttonIndex]]; // UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:string delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; // [alert show]; NSLog(@"%@",string); } |
相关文章推荐
- iOS开发 对话框UIActionSheet和UIAlertView用法
- UIActionSheet操作表单-IOS开发
- iOS开发之自定义系统的UIActionSheet修改按钮的属性
- IOS开发UI篇之──自定义UIActionSheet
- IOS开发之自定义UIActionSheet
- IOS开发UI篇之──自定义UIActionSheet
- IOS开发UI篇之──自定义UIActionSheet
- UIActionSheet操作表单-IOS开发
- iOS开发 提示框- UIAlertController(是UIAlertView和UIActionSheet的合二为一)
- IOS开发问题解决之UIAlertView调用UIActionSheet后灰色背景一直存在
- IOS开发UI篇之──自定义UIActionSheet【转】
- iOS开发:UIActionSheet与UIAlertView
- Swift开发IOS-UIActionSheet
- iOS开发-UIActionSheet和UIAlertController
- IOS开发之自定义UIActionSheet
- ios-day05-05(创建弹框(对话框),UIAlertView、UIActionSheet)
- IOS 开发学习十六 UIActionSheet的使用
- iOS开发之基础视图—— UIActionSheet
- iOS开发基础 - UIActionSheet
- iOS开发6:UIActionSheet与UIAlertView