操作表的创建
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"分享" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"警告按钮" otherButtonTitles:@"动作1",@"动作2", nil];
sheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[sheet showInView:self.view];
有工具条/标签条时的操作
- 一般情况
showInView - 工具条的情况下
showFromToolbar - 标签条的情况下
showFromTabbar
操作表的代理方法 UIActionSheetDelegate
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"操作表显示前被调用");
}
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"操作表显示后被调用");
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet
{
NSLog(@"操作表中被强制关闭被调用");
/*例如操作表显示时应用程序突然关闭等场合 触摸取消按钮不调用此方法*/
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"点击操作表中的任意按钮时被调用");
NSLog(@"%ld",buttonIndex);
}
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"操作表关闭前调用");
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"操作表关闭后调用");
}