UIActionSheet操作表單

什麼是操作表單?看圖:

 

一看圖就明白了,毋需多說。

 

  1. UIActionSheet* mySheet = [[UIActionSheet alloc]  
  2.                            initWithTitle:@"ActionChoose"   
  3.                            delegate:self   
  4.                            cancelButtonTitle:@"Cancel"  
  5.                            destructiveButtonTitle:@"Destroy"  
  6.                            otherButtonTitles:@"OK", nil];  
  7.     [mySheet showInView:self.view];  


與UIAlertView類似,我們也是在委託方法裏處理按下按鈕後的動作。記得在所委託的類加上UIActionSheetDelegate。

 

  1. - (void)actionSheetCancel:(UIActionSheet *)actionSheet{  
  2.     //  
  3. }  
  4. - (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{  
  5.     //  
  6. }  
  7. -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{  
  8.     //  
  9. }  
  10. -(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{  
  11.     //  
  12. }  


看到那個紅色的按鈕沒?那是ActionSheet支持的一種所謂的銷燬按鈕,對某戶的某個動作起到警示作用,

比如永久性刪除一條消息或者日誌。如果你指定了一個銷燬按鈕他就會以紅色高亮顯示:

 

  1. mySheet.destructiveButtonIndex=1;  

與導航欄類似,操作表單也支持三種風格 :

 

  1. UIActionSheetStyleDefault              //默認風格:灰色背景上顯示白色文字  
  2. UIActionSheetStyleBlackTranslucent     //透明黑色背景,白色文字  
  3. UIActionSheetStyleBlackOpaque          //純黑背景,白色文字  

用法用例:

mySheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;

顯示ActionSheet有三種方法:

1.在一個視圖內部顯示,可以用showInView

[mySheet showInView:self];

2.如果要將ActonSheet 與工具欄或者標籤欄對齊,可以使用showFromToolBar或showFromTabBar

[mySheet showFromToolBar:toolbar];

[mySheet showFromTabBar:tabbar];
解除操作表單

用戶按下按鈕之後,Actionsheet就會消失——除非應用程序有特殊原因,需要用戶按下做個按鈕。用dismiss方法可令表單消失:

 

  1. [mySheet dismissWithClickButtonIndex:1 animated:YES];  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章