Skip to content

showActionSheet ​

接口说明 ​

showActionSheet:options: 用于从底部弹出操作菜单 Action Sheet,向用户展示一组可选择的操作项。

常用于让用户在多个操作中进行选择,例如“拍照 / 从相册选择”“编辑 / 删除 / 取消”等场景。

类型声明 ​

objectivec
/**
 Options for configuring action sheet display behavior.
 */
@interface SUDOPShowActionSheetOptions : NSObject

/**
 The warning or alert text displayed at the top of the action sheet.
 (e.g., "Are you sure?", "This action cannot be undone.")
 */
@property(nonatomic, strong) NSString *alertText;

/**
 The list of button titles to be displayed in the action sheet.
 The maximum length of the array is 6.
 */
@property(nonatomic, strong) NSArray<NSString *> *itemList;

/**
 The text color of the buttons (e.g., "#FF0000").
 */
@property(nonatomic, strong) NSString *itemColor;

@end

方法声明 ​

objectivec
/**
 Displays an action sheet (bottom sheet) with a list of selectable options.
 @param stateHandle The state handle object that manages the operation state and callbacks.
 @param options The options configuration for the action sheet (alert text, item list, item color, etc.).
 */
- (void)showActionSheet:(id<SUDOPStateHandle>)stateHandle
                options:(SUDOPShowActionSheetOptions *)options;

参数说明 ​

SUDOPShowActionSheetOptions ​

参数类型是否必填说明
alertTextNSString *否Action Sheet 顶部的提示或警告文案,例如“确定删除吗?”“该操作不可撤销”。
itemListNSArray<NSString *> *是操作按钮标题列表,数组最大长度为 6。
itemColorNSString *否操作按钮的文字颜色,例如 #FF0000。

方法参数 ​

参数类型是否必填说明
stateHandleid<SUDOPStateHandle>是状态句柄对象,用于管理当前操作状态及回调。
optionsSUDOPShowActionSheetOptions *是Action Sheet 展示配置对象,包含顶部提示文案、操作项列表、按钮颜色等配置。

使用示例 ​

展示基础 Action Sheet ​

objectivec
id<SUDOPStateHandle> stateHandle = self.stateHandle;

SUDOPShowActionSheetOptions *options = [[SUDOPShowActionSheetOptions alloc] init];
options.itemList = @[@"拍照", @"从相册选择"];

[self showActionSheet:stateHandle options:options];

展示带提示文案的 Action Sheet ​

objectivec
SUDOPShowActionSheetOptions *options = [[SUDOPShowActionSheetOptions alloc] init];
options.alertText = @"请选择图片来源";
options.itemList = @[@"拍照", @"从相册选择"];

[self showActionSheet:self.stateHandle options:options];

设置按钮文字颜色 ​

objectivec
SUDOPShowActionSheetOptions *options = [[SUDOPShowActionSheetOptions alloc] init];
options.alertText = @"删除后不可恢复";
options.itemList = @[@"删除"];
options.itemColor = @"#FF0000";

[self showActionSheet:self.stateHandle options:options];

多操作项示例 ​

objectivec
SUDOPShowActionSheetOptions *options = [[SUDOPShowActionSheetOptions alloc] init];
options.alertText = @"请选择操作";
options.itemList = @[@"编辑", @"分享", @"收藏", @"删除"];
options.itemColor = @"#333333";

[self showActionSheet:self.stateHandle options:options];

处理流程 ​

  1. 业务侧创建 SUDOPShowActionSheetOptions 对象。
  2. 设置操作项列表 itemList。
  3. 根据需要设置顶部提示文案 alertText。
  4. 根据需要设置按钮文字颜色 itemColor。
  5. 调用 showActionSheet:options: 展示 Action Sheet。
  6. 用户点击某个操作项或取消弹窗。
  7. SDK 通过状态回调返回用户选择结果或取消结果,具体回调数据结构以 SDK 实际实现为准。

注意事项 ​

  • stateHandle 不应为空,否则 SDK 可能无法正确管理当前操作状态或回调。
  • options 不应为空。
  • itemList 建议必填,且至少包含一个操作项。
  • itemList 最大长度为 6,超过限制时 SDK 可能截断、报错或展示异常,具体表现以 SDK 实现为准。
  • itemList 中的每一项建议为非空字符串。
  • alertText 为可选字段,不设置时 Action Sheet 顶部可不展示提示文案。
  • itemColor 建议使用合法的颜色字符串,例如 #FF0000、#333333。
  • 如果需要突出危险操作,例如“删除”,可以将 itemColor 设置为红色。
  • 用户点击具体操作项后的返回结果通常通过 stateHandle 相关回调获取。
  • 该方法无同步返回值,展示结果、选择结果或异常信息应以 SDK 回调或状态回调为准。