显示菜单的方法:
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: