首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >创建UIActionSheet

创建UIActionSheet
EN

Stack Overflow用户
提问于 2013-06-21 04:30:27
回答 4查看 83.5K关注 0票数 58

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

EN

回答 4

Stack Overflow用户

发布于 2013-06-21 04:34:44

您需要使用UIActionSheet

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

然后,您可以使用以下命令引用操作表:

代码语言:javascript
复制
  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];

然后,您必须处理每个调用。

代码语言:javascript
复制
- (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,此选项已弃用

票数 169
EN

Stack Overflow用户

发布于 2013-06-21 04:32:53

请看一下UIActionSheet文档。

代码语言:javascript
复制
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];
票数 11
EN

Stack Overflow用户

发布于 2013-06-21 04:34:51

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

代码语言:javascript
复制
    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 (代码来自本教程)

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17223210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档