iOS開發:關于ActionSheet
顯示菜單的方法:
1、showInView
2、showFromToolBar:和showFromTabBar
視圖控制類需要是現實協議接口UIActionSheetDelegate
- @interface HelloController :UIViewController<UIActionSheetDelegate>
- @end
主要實現代碼:
- - (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];
- }
類學習
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類呈現給用戶一系列交替選項用于決定如何處理所給的任務。你也可以使用動作表來提示用戶確認具有潛在危險的動作。動作表包含可選標題和1個或多個按鈕,每個按鈕對應響應所給的動作。
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:
備注:比對學習下UIAlertView,你會發現這兩個類基本類似
這里還有一組常量值
UIActionSheetStyle
Specifies the style of an actionsheet.
- typedef enum {
- UIActionSheetStyleAutomatic =-1,
- UIActionSheetStyleDefault = UIBarStyleDefault,
- UIActionSheetStyleBlackTranslucent =UIBarStyleBlackTranslucent,
- UIActionSheetStyleBlackOpaque =UIBarStyleBlackOpaque,
- } UIActionSheetStyle;
Constants
UIActionSheetStyleAutoma
UIActionSheetStyleDefaul
UIActionSheetStyleBlackT
UIActionSheetStyleBlackO
協議接口學習
UIActionSheetDelegate協議接口
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: