创建UIActionSheet

mbu*_*tan 58 objective-c uiactionsheet ios

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

在此输入图像描述

Apo*_*ARE 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];
Run Code Online (Sandbox Code Playgroud)

然后你必须处理每个电话.

- (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;
 }
}
Run Code Online (Sandbox Code Playgroud)

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

  • +!是唯一一个称之为"UIActionSheet"的人(以及提供一个好的答案). (5认同)
  • 在iOS 8中有一个新的UIAlertController https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertController_class/index.html#//apple_ref/occ/cl/UIAlertController (2认同)

Rob*_*Rob 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];
Run Code Online (Sandbox Code Playgroud)


7c9*_*fdf 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];
Run Code Online (Sandbox Code Playgroud)

实现UISctionSheetDelegate以响应按钮操作.

有关详细信息,请查看本教程:http://mobile.tutsplus.com/tutorials/iphone/uiactionsheet_uiactionsheetdelegate(代码来自本教程)