【问题标题】:Creating UIActionSheet [duplicate]创建 UIActionSheet [重复]
【发布时间】:2013-06-20 20:30:27
【问题描述】:

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

【问题讨论】:

  • 这道题的题目和热度比重复题要好很多。最好重新打开这个问题,以便添加更新的答案。
  • 请投票重新开放。
  • @Suragch 你是对的。它比其他链接更有帮助和易于理解

标签: ios objective-c uiactionsheet


【解决方案1】:

您需要使用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

【讨论】:

  • +!因为是唯一一个将其称为UIActionSheet 的人(并提供了一个很好的答案)。
  • 当我看到这个问题时,我确实在开发我的应用程序!它来自我的代码逐字;)
  • 它也可以在不添加 UIActionSheetDelegate 的情况下工作。我想知道如何......
  • 在 iOS 8 中有一个新的 UIAlertController developer.apple.com/library/ios/documentation/uikit/reference/…
  • 在 14 年 9 月 24 日的评论和编辑中,有一个新的 UIAlertController 和 UIActionSheet 在 iOS 8 中已被弃用,但说它已经“改变”并不完全准确。最好包含指向类引用的链接,但说它已被弃用而不是更改。
【解决方案2】:

查看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];

【讨论】:

    【解决方案3】:

    它被称为 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(代码来自本教程)

    【讨论】:

      【解决方案4】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-15
        • 2017-09-15
        • 1970-01-01
        相关资源
        最近更新 更多