溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

[iPhone開(kāi)發(fā)之控件的使用]UIActionSheet的各種屬性、方法及代理的使用

發(fā)布時(shí)間:2020-06-19 21:23:57 來(lái)源:網(wǎng)絡(luò) 閱讀:469 作者:新風(fēng)作浪 欄目:開(kāi)發(fā)技術(shù)
[c-sharp] view plaincopy
  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  無(wú)例 
  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是否可見(jiàn),這是一個(gè)只讀屬性  
  41.     BOOL a = actionSheetTest.visible;  
  42.     NSLog(@"%d",a);  
  43.       
  44.     //不考慮指定索引的按鈕的動(dòng)作,可以設(shè)置是否有動(dòng)畫  
  45.     [actionSheetTest dismissWithClickedButtonIndex:0 animated:NO];  
  46.       
  47.     //設(shè)置標(biāo)題  
  48.     actionSheetTest.title = @"ActionSheetTitle";  
  49.       
  50.     //通過(guò)給定標(biāo)題添加按鈕  
  51.     [actionSheetTest addButtonWithTitle:@"addButtonWithTitle"];  
  52.       
  53.     //按鈕總數(shù)  
  54.     numOfBtn.text = [NSString stringWithFormat:@"%d",actionSheetTest.numberOfButtons];  
  55.       
  56.     //獲取指定索引的標(biāo)題  
  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.     //獲取第一個(gè)其他按鈕的索引  
  66.     firstOtherBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.firstOtherButtonIndex];  
  67.       
  68.     //設(shè)置actionSheet出現(xiàn)的方式  
  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. //根據(jù)被點(diǎn)擊按鈕的索引處理點(diǎn)擊事件  
  111. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {  
  112.     NSLog(@"clickedButtonAtIndex:%d",buttonIndex);  
  113. }  
  114. //ActionSheet已經(jīng)消失時(shí)  
  115. - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {  
  116.     NSLog(@"didDismissWithButtonIndex:%d",buttonIndex);  
  117. }  
  118. //ActionSheet即將消失時(shí)  
  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已經(jīng)顯示時(shí)  
  128. - (void)didPresentActionSheet:(UIActionSheet *)actionSheet {  
  129.     NSLog(@"didPresentActionSheet%@",actionSheet);  
  130. }  
  131. //ActionSheet即將顯示時(shí)  
  132. - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {  
  133.     NSLog(@"willPresentActionSheet%@",actionSheet);  
  134. }  

  1. @end  


原文轉(zhuǎn)載:http://blog.csdn.net/banyingli/article/details/6167561



向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI