[iPhone开发之控件的使用]UIActionSheet的各种属性、方法及代理的使用
来源:互联网 发布:橙光文字游戏制作软件 编辑:程序博客网 时间:2024/06/05 13:21
- #import "ActionSheetTestViewController.h"
- @implementation ActionSheetTestViewController
- /*
- Tasks
- Creating Action Sheets
- – initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:
- Setting Properties
- delegate property
- title property
- visible property
- actionSheetStyle property 无例
- Configuring Buttons
- – addButtonWithTitle:
- numberOfButtons property
- – buttonTitleAtIndex:
- cancelButtonIndex property
- destructiveButtonIndex property
- firstOtherButtonIndex property
- Displaying
- – showFromTabBar:
- – showFromToolbar:
- – showInView:
- Dismissing
- – dismissWithClickedButtonIndex:animated:
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- UILabel *numOfBtn = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 10.0, 30.0, 30.0)];
- UILabel *titleOfBtn = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 10.0, 100.0, 30.0)];
- UILabel *cancelBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(200.0, 10.0, 30.0, 30.0)];
- UILabel *destructiveBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 50.0, 30.0, 30.0)];
- UILabel *firstOtherBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 50.0, 30.0, 30.0)];
- UIActionSheet *actionSheetTest = [[UIActionSheet alloc]initWithTitle:@"ActionSheetTest"
- delegate:self
- cancelButtonTitle:@"CancelButton"
- destructiveButtonTitle:@"RedButton"
- otherButtonTitles:@"OtherButton1",@"OtherButton2",nil];
- //看actionSheet是否可见,这是一个只读属性
- BOOL a = actionSheetTest.visible;
- NSLog(@"%d",a);
- //不考虑指定索引的按钮的动作,可以设置是否有动画
- [actionSheetTest dismissWithClickedButtonIndex:0 animated:NO];
- //设置标题
- actionSheetTest.title = @"ActionSheetTitle";
- //通过给定标题添加按钮
- [actionSheetTest addButtonWithTitle:@"addButtonWithTitle"];
- //按钮总数
- numOfBtn.text = [NSString stringWithFormat:@"%d",actionSheetTest.numberOfButtons];
- //获取指定索引的标题
- titleOfBtn.text = [actionSheetTest buttonTitleAtIndex:4];
- //获取取消按钮的索引
- cancelBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.cancelButtonIndex];
- //获取红色按钮的索引
- destructiveBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.destructiveButtonIndex];
- //获取第一个其他按钮的索引
- firstOtherBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.firstOtherButtonIndex];
- //设置actionSheet出现的方式
- [actionSheetTest showInView:self.view];//or [actionSheetTest showFromTabBar:] or [actionSheetTest showFromToolBar:]
- [self.view addSubview:numOfBtn];
- [self.view addSubview:titleOfBtn];
- [self.view addSubview:cancelBtnIndex];
- [self.view addSubview:destructiveBtnIndex];
- [self.view addSubview:firstOtherBtnIndex];
- [actionSheetTest release];
- [numOfBtn release];
- [titleOfBtn release];
- [cancelBtnIndex release];
- [destructiveBtnIndex release];
- [firstOtherBtnIndex release];
- [super viewDidLoad];
- }
- /*
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- */
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (void)dealloc {
- [super dealloc];
- }
- #pragma mark -- UIActionSheetDelegate --
- //根据被点击按钮的索引处理点击事件
- - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
- NSLog(@"clickedButtonAtIndex:%d",buttonIndex);
- }
- //ActionSheet已经消失时
- - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
- NSLog(@"didDismissWithButtonIndex:%d",buttonIndex);
- }
- //ActionSheet即将消失时
- - (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {
- NSLog(@"willDismissWithButtonIndex:%d",buttonIndex);
- }
- //
- - (void)actionSheetCancel:(UIActionSheet *)actionSheet {
- NSLog(@"actionSheetCancel");
- }
- //ActionSheet已经显示时
- - (void)didPresentActionSheet:(UIActionSheet *)actionSheet {
- NSLog(@"didPresentActionSheet%@",actionSheet);
- }
- //ActionSheet即将显示时
- - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
- NSLog(@"willPresentActionSheet%@",actionSheet);
- }
- @end
原文转载:http://blog.csdn.net/banyingli/article/details/6167561
- [iPhone开发之控件的使用]UIActionSheet的各种属性、方法及代理的使用
- [iPhone开发之控件的使用]UIActionSheet的各种属性、方法及代理的使用
- [iPhone开发之控件的使用]UIAlertView的各种属性、方法及代理的使用
- [iPhone开发之控件的使用]UIAlertView的各种属性、方法及代理的使用
- [iPhone开发之控件的使用]UISegmentedControl的各种属性与方法的使用
- [iPhone开发之控件的使用]UILabel的各种属性与方法的使用
- [iPhone开发之控件的使用]UILabel的各种属性与方法的使用
- [iPhone开发之控件的使用]UILabel的各种属性与方法的使用
- [iPhone开发之控件的使用]UISegmentedControl的各种属性与方法的使用
- iPhone开发之UIActionSheet的使用
- UIAlertView的各种属性、方法及代理的使用
- UIAlertView的各种属性、方法及代理的使用
- UIAlertView的各种属性、方法及代理的使用
- iOS之UIActionSheet的使用
- iPhone开发之Delegate(代理、委托)的理解和使用
- iPhone开发之Delegate(代理、委托)的理解和使用
- UIAlertView提示控件和UIActionSheet的使用
- iOS 开发之TextView的提示文字属性使用和代理方法使用
- 读《乔布斯传》的心得体会-
- Lfs Common --> Log
- symbian string to TTime
- 关于String转码成URL遇到的问题
- 终端服务器超出了最大允许连接数”的解决方法汇总
- [iPhone开发之控件的使用]UIActionSheet的各种属性、方法及代理的使用
- 从MTK的scat文件谈ROM和RAM的分配,管理和问题解决
- oracle监听器配置
- checkout失败(svn服务器)
- JSP-隐式对象
- Matlab 执行engEvalString命令介绍
- vim菜鸟学习-中级篇2(经典配置)
- Java编程中“为了性能”需做的26件事
- weblogic 执行任务OutOfMemoryError错误