[iPhone开发之控件的使用]UIActionSheet的各种属性、方法及代理的使用

简介:
[c-sharp]  view plain copy
  1. #import "ActionSheetTestViewController.h"  
  2. @implementation ActionSheetTestViewController  
  3. /* 
  4. Tasks 
  5.   
  6. Creating Action Sheets 
  7.     – initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:   
  8.     Setting Properties 
  9.     delegate  property   
  10.     title  property   
  11.     visible  property   
  12.     actionSheetStyle  property  无例 
  13. Configuring Buttons 
  14.     – addButtonWithTitle:   
  15.     numberOfButtons  property   
  16.     – buttonTitleAtIndex:   
  17.     cancelButtonIndex  property   
  18.     destructiveButtonIndex  property   
  19.     firstOtherButtonIndex  property   
  20. Displaying 
  21.     – showFromTabBar:   
  22.     – showFromToolbar:   
  23.     – showInView:   
  24. Dismissing 
  25.     – dismissWithClickedButtonIndex:animated:   
  26. */  
  27.   
  28. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  29. - (void)viewDidLoad {  
  30.     UILabel *numOfBtn = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 10.0, 30.0, 30.0)];  
  31.     UILabel *titleOfBtn = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 10.0, 100.0, 30.0)];  
  32.     UILabel *cancelBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(200.0, 10.0, 30.0, 30.0)];  
  33.     UILabel *destructiveBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 50.0, 30.0, 30.0)];  
  34.     UILabel *firstOtherBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 50.0, 30.0, 30.0)];  
  35.     UIActionSheet *actionSheetTest = [[UIActionSheet alloc]initWithTitle:@"ActionSheetTest"   
  36.                                 delegate:self  
  37.                                 cancelButtonTitle:@"CancelButton"   
  38.                                 destructiveButtonTitle:@"RedButton"   
  39.                                 otherButtonTitles:@"OtherButton1",@"OtherButton2",nil];  
  40.     //看actionSheet是否可见,这是一个只读属性  
  41.     BOOL a = actionSheetTest.visible;  
  42.     NSLog(@"%d",a);  
  43.       
  44.     //不考虑指定索引的按钮的动作,可以设置是否有动画  
  45.     [actionSheetTest dismissWithClickedButtonIndex:0 animated:NO];  
  46.       
  47.     //设置标题  
  48.     actionSheetTest.title = @"ActionSheetTitle";  
  49.       
  50.     //通过给定标题添加按钮  
  51.     [actionSheetTest addButtonWithTitle:@"addButtonWithTitle"];  
  52.       
  53.     //按钮总数  
  54.     numOfBtn.text = [NSString stringWithFormat:@"%d",actionSheetTest.numberOfButtons];  
  55.       
  56.     //获取指定索引的标题  
  57.     titleOfBtn.text = [actionSheetTest buttonTitleAtIndex:4];  
  58.       
  59.     //获取取消按钮的索引  
  60.     cancelBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.cancelButtonIndex];  
  61.       
  62.     //获取红色按钮的索引  
  63.     destructiveBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.destructiveButtonIndex];  
  64.       
  65.     //获取第一个其他按钮的索引  
  66.     firstOtherBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.firstOtherButtonIndex];  
  67.       
  68.     //设置actionSheet出现的方式  
  69.     [actionSheetTest showInView:self.view];//or [actionSheetTest showFromTabBar:] or [actionSheetTest showFromToolBar:]  
  70.       
  71.     [self.view addSubview:numOfBtn];  
  72.     [self.view addSubview:titleOfBtn];  
  73.     [self.view addSubview:cancelBtnIndex];  
  74.     [self.view addSubview:destructiveBtnIndex];  
  75.     [self.view addSubview:firstOtherBtnIndex];  
  76.       
  77.     [actionSheetTest release];  
  78.     [numOfBtn release];  
  79.     [titleOfBtn release];  
  80.     [cancelBtnIndex release];  
  81.     [destructiveBtnIndex release];  
  82.     [firstOtherBtnIndex release];  
  83.       
  84.     [super viewDidLoad];  
  85. }  
  86.   
  87. /* 
  88. // Override to allow orientations other than the default portrait orientation. 
  89. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
  90.     // Return YES for supported orientations 
  91.     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
  92. } 
  93. */  
  94. - (void)didReceiveMemoryWarning {  
  95.     // Releases the view if it doesn't have a superview.  
  96.     [super didReceiveMemoryWarning];  
  97.       
  98.     // Release any cached data, images, etc that aren't in use.  
  99. }  
  100. - (void)viewDidUnload {  
  101.     // Release any retained subviews of the main view.  
  102.     // e.g. self.myOutlet = nil;  
  103. }  
  104.   
  105. - (void)dealloc {  
  106.     [super dealloc];  
  107. }  
  108.  
  109. #pragma mark -- UIActionSheetDelegate --  
  110. //根据被点击按钮的索引处理点击事件  
  111. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {  
  112.     NSLog(@"clickedButtonAtIndex:%d",buttonIndex);  
  113. }  
  114. //ActionSheet已经消失时  
  115. - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {  
  116.     NSLog(@"didDismissWithButtonIndex:%d",buttonIndex);  
  117. }  
  118. //ActionSheet即将消失时  
  119. - (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {  
  120.     NSLog(@"willDismissWithButtonIndex:%d",buttonIndex);  
  121. }  
  122. //  
  123. - (void)actionSheetCancel:(UIActionSheet *)actionSheet {  
  124.     NSLog(@"actionSheetCancel");  
  125.       
  126. }  
  127. //ActionSheet已经显示时  
  128. - (void)didPresentActionSheet:(UIActionSheet *)actionSheet {  
  129.     NSLog(@"didPresentActionSheet%@",actionSheet);  
  130. }  
  131. //ActionSheet即将显示时  
  132. - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {  
  133.     NSLog(@"willPresentActionSheet%@",actionSheet);  
  134. }  

  1. @end  





  本文转自新风作浪 51CTO博客,原文链接:http://blog.51cto.com/duxinfeng/1208757,如需转载请自行联系原作者

相关文章
|
4月前
|
编解码 测试技术 iOS开发
iPhone 屏幕尺寸和开发适配
【10月更文挑战第23天】iPhone 的屏幕尺寸变化给开发者带来了一定的挑战,但也为创新提供了机遇。通过深入了解不同屏幕尺寸的特点,遵循适配原则和策略,运用合适的技巧和方法,我们能够为用户提供在不同 iPhone 机型上都具有良好体验的应用。在未来,随着技术的不断进步,我们还需要持续学习和适应,以满足用户对优质应用体验的不断追求。
|
4月前
|
编解码 iOS开发 UED
响应式设计在 iPhone 开发适配中的具体应用
【10月更文挑战第23天】响应式设计在 iPhone 开发适配中扮演着至关重要的角色,它能够帮助我们打造出适应不同屏幕尺寸和用户需求的高质量应用。通过合理运用响应式设计的原则和方法,我们可以在提供良好用户体验的同时,提高开发效率和应用的可维护性。
|
7月前
|
数据采集 iOS开发 Python
Chatgpt教你开发iPhone风格计算器,Python代码实现
Chatgpt教你开发iPhone风格计算器,Python代码实现
77 1
|
网络安全 开发工具 数据安全/隐私保护
如何把ipa文件(iOS安装包)安装到iPhone手机上? 附方法汇总
如何把ipa文件(iOS安装包)安装到iPhone手机上? 附方法汇总
|
10月前
|
网络安全 开发工具 数据安全/隐私保护
如何把 ipa 文件 (iOS 安装包) 安装到 iPhone 手机上? 附方法汇总
如何把 ipa 文件 (iOS 安装包) 安装到 iPhone 手机上? 附方法汇总
|
网络安全 开发工具 数据安全/隐私保护
如何把 ipa 文件 (iOS 安装包) 安装到 iPhone 手机上? 附方法汇总
苹果 APP 安装包 ipa 如何安装在手机上?很多人不知道怎么把 ipa 文件安装到手机上,这里就整理了苹果 APP 安装到 iOS 设备上的方式,仅供参考
|
Web App开发 网络虚拟化 iOS开发
如何获取苹果设备的UDID(iPhone/iPad UDID查询方法)
如何获取苹果设备的UDID(iPhone/iPad UDID查询方法)
|
iOS开发 开发者
ios app安装到iphone手机的方法
ios app安装到iphone有三种不同的方法,各种方法的使用场景是不同的,你可以根据不同的场景来使用其中一种方法。
710 0
|
iOS开发
iphone中获取文件路径的4种方法
iphone中获取文件路径的4种方法
453 0
|
iOS开发
方法:怎样把手机号码导入苹果iphone手机通讯录?
第(1)步:首先你得打开你的苹果iphone手机,再次,你得在电脑上打开软件,金芝号码提取导入助手。第(2)步:然后你来到电脑上,把你自己准备好的号码和姓铭都复制好,打开电脑软件,把它们粘贴到软件的第三个功能模块:导入通讯录。然后点上面的“生成通讯录”。你将得到一个文件。第(3)步:最后你从电脑上的徽xin或者电脑Q把这个文件发给你的苹果iphone手机,在手机上打开它,其他应用方式打开,选通讯录,储存,就可以把号码导入苹果iphone手机通讯录。
方法:怎样把手机号码导入苹果iphone手机通讯录?