采用滑动方式呈现在屏幕上,等待用户响应
显示菜单的方法:
1、showInView
2、showFromToolBar:和showFromTabBar
视图控制类需要是现实协议接口UIActionSheetDelegate
@interface HelloController : UIViewController <UIActionSheetDelegate>
@end
主要实现代码:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
printf("User Pressed Button %d\n", buttonIndex + 1);
[actionSheet release];
}
- (void) presentSheet
{
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle: @"File Management"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete File"
otherButtonTitles:@"Rename File", @"Email File", nil];
[menu showInView:self.view];
}
类学习
UIActionSheet类
继承UIView
Use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task. You can also use action sheets to prompt the user to confirm a potentially dangerous action. The action sheet contains an optional title and one or more buttons, each of which corresponds to 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 action sheet.
typedef enum {
UIActionSheetStyleAutomatic = -1,
UIActionSheetStyleDefault = UIBarStyleDefault,
UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
UIActionSheetStyleBlackOpaque = UIBarStyleBlackOpaque,
} UIActionSheetStyle;
Constants
UIActionSheetStyleAutomatic
Takes the appearance of the bottom bar if specified; otherwise, same as UIActionSheetStyleDefault.
UIActionSheetStyleDefault
The default style.
UIActionSheetStyleBlackTranslucent
A black translucent style.
UIActionSheetStyleBlackOpaque
A black opaque style.
协议接口学习
UIActionSheetDelegate协议接口
The UIActionSheetDelegate protocol defines the methods a delegate of a UIActionSheet object should implement. The delegate implements the button actions and any other custom behavior. Some of the methods defined in this protocol are optional.
Responding to Actions
– actionSheet:clickedButtonAtIndex:
Customizing Behavior
– willPresentActionSheet:
– didPresentActionSheet:
– actionSheet:willDismissWithButtonIndex:
– actionSheet:didDismissWithButtonIndex:
Canceling
– actionSheetCancel:
看来,这里和UIAlertViewDelegate接口也类似,学起来也方便多了,good