58

我想创建这种菜单,当然还有其他菜单按钮。是否有代表它的默认视图控制器,或者我必须获取图像并自己创建它。

在此处输入图像描述

4

4 回答 4

169

您需要使用UIActionSheet.

首先,您需要添加UIActionSheetDelegate到您的 ViewController.h 文件中。

然后你可以参考一个动作表:

  UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select Sharing option:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
                        @"Share on Facebook",
                        @"Share on Twitter",
                        @"Share via E-mail",
                        @"Save to Camera Roll",
                        @"Rate this App",
                        nil];
   popup.tag = 1;
  [popup showInView:self.view];

然后您必须处理每个呼叫。

- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex {

  switch (popup.tag) {
    case 1: {
        switch (buttonIndex) {
            case 0:
                [self FBShare];
                break;
            case 1:
                [self TwitterShare];
                break;
            case 2:
                [self emailContent];
                break;
            case 3:
                [self saveContent];
                break;
            case 4:
                [self rateAppYes];
                break;
            default:
                break;
        }
        break;
    }
    default:
        break;
 }
}

这已被 iOS 8.x 弃用 https://developer.apple.com/documentation/uikit/uialertcontroller#//apple_ref/occ/cl/UIAlertController

于 2013-06-20T20:34:43.877 回答
11

查看UIActionSheet文档。

NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title
NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles
NSString *other1 = @"Other Button 1";
NSString *other2 = @"Other Button 2";
NSString *other3 = @"Other Button 3";
NSString *cancelTitle = @"Cancel Button";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
                              initWithTitle:actionSheetTitle
                              delegate:self
                              cancelButtonTitle:cancelTitle
                              destructiveButtonTitle:destructiveTitle
                              otherButtonTitles:other1, other2, other3, nil];
[actionSheet showInView:self.view];
于 2013-06-20T20:32:52.920 回答
5

它被称为 UIActionSheet:您可以像这样创建一个:

    NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title
NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles
NSString *other1 = @"Other Button 1";
NSString *other2 = @"Other Button 2";
NSString *other3 = @"Other Button 3";
NSString *cancelTitle = @"Cancel Button";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
                              initWithTitle:actionSheetTitle
                              delegate:self
                              cancelButtonTitle:cancelTitle
                              destructiveButtonTitle:destructiveTitle
                              otherButtonTitles:other1, other2, other3, nil];
[actionSheet showInView:self.view];

实现 UISctionSheetDelegate 以响应按钮操作。

查看本教程以获取更多信息:http: //mobile.tutsplus.com/tutorials/iphone/uiactionsheet_uiactionsheetdelegate(代码来自本教程)

于 2013-06-20T20:34:51.113 回答
3

您要查找的内容称为操作表。在此处阅读有关它的更多信息http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIActionSheet_Class/Reference/Reference.html

于 2013-06-20T20:33:20.273 回答