iOS開發(fā):關(guān)于ActionSheet
顯示菜單的方法:
1、showInView
2、showFromToolBar:和showFromTabBar
視圖控制類需要是現(xiàn)實(shí)協(xié)議接口UIActionSheetDelegate
- @interface HelloController :UIViewController<UIActionSheetDelegate>
- @end
主要實(shí)現(xiàn)代碼:
- - (void)actionSheet:(UIActionSheet*)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex
- {
- printf("User Pressed Button %d\n",buttonIndex + 1);
- [actionSheet release];
- }
- - (void) presentSheet
- {
- UIActionSheet *menu = [[UIActionSheetalloc]
- initWithTitle: @"FileManagement"
- delegate:self
- cancelButtonTitle:@"Cancel"
- destructiveButtonTitle:@"DeleteFile"
- otherButtonTitles:@"Rename File", @"EmailFile", nil];
- [menu showInView:self.view];
- }
類學(xué)習(xí)
UIActionSheet類
繼承UIView
Use the UIActionSheet class to presentthe user with a set of alternatives for how to proceed with a giventask. You can also use action sheets to prompt the user to confirma potentially dangerous action. The action sheet contains anoptional title and one or more buttons, each of which correspondsto an action to take.
使用UIActionSheet類呈現(xiàn)給用戶一系列交替選項(xiàng)用于決定如何處理所給的任務(wù)。你也可以使用動(dòng)作表來(lái)提示用戶確認(rèn)具有潛在危險(xiǎn)的動(dòng)作。動(dòng)作表包含可選標(biāo)題和1個(gè)或多個(gè)按鈕,每個(gè)按鈕對(duì)應(yīng)響應(yīng)所給的動(dòng)作。
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
Presenting the Action Sheet
- –showFromTabBar:
- –showFromToolbar:
- –showInView:
- –showFromBarButtonItem:animated:
- –showFromRect:inView:animated:
Dismissing the Action Sheet
- –dismissWithClickedButtonIndex:animated:
備注:比對(duì)學(xué)習(xí)下UIAlertView,你會(huì)發(fā)現(xiàn)這兩個(gè)類基本類似
這里還有一組常量值
UIActionSheetStyle
Specifies the style of an actionsheet.
- typedef enum {
- UIActionSheetStyleAutomatic =-1,
- UIActionSheetStyleDefault = UIBarStyleDefault,
- UIActionSheetStyleBlackTranslucent =UIBarStyleBlackTranslucent,
- UIActionSheetStyleBlackOpaque =UIBarStyleBlackOpaque,
- } UIActionSheetStyle;
Constants
UIActionSheetStyleAutoma
UIActionSheetStyleDefaul
UIActionSheetStyleBlackT
UIActionSheetStyleBlackO
協(xié)議接口學(xué)習(xí)
UIActionSheetDelegate協(xié)議接口
The UIActionSheetDelegate protocoldefines the methods a delegate of a UIActionSheet object shouldimplement. The delegate implements the button actions and any othercustom behavior. Some of the methods defined in this protocol areoptional.
Responding to Actions
- –actionSheet:clickedButtonAtIndex:
Customizing Behavior
- –willPresentActionSheet:
- –didPresentActionSheet:
- –actionSheet:willDismissWithButtonIndex:
- –actionSheet:didDismissWithButtonIndex:
Canceling
- –actionSheetCancel: