Skip to content

showModal ​

接口说明 ​

showModal:options: 用于向用户展示模态弹窗 Modal,支持标题、内容、确认按钮、取消按钮以及输入框等配置。

该接口常用于展示确认提示、警告信息、用户二次确认或简单文本输入场景,例如“确认删除”“请输入昵称”等。

类型声明 ​

objectivec
/**
 Options for configuring modal dialog box display behavior.
 */
@interface SUDOPShowModalOptions : NSObject

/**
 The title text of the modal dialog.
 */
@property(nonatomic, strong) NSString *title;

/**
 The content message text of the modal dialog.
 */
@property(nonatomic, strong) NSString *content;

/**
 Whether to show the cancel button.
 When set to YES, a cancel button will be displayed alongside the confirm button.
 */
@property(nonatomic, assign) BOOL showCancel;

/**
 The text of the cancel button.
 Maximum length is 4 characters.
 */
@property(nonatomic, strong) NSString *cancelText;

/**
 The text color of the cancel button.
 Must be a hex format color string (e.g., "#FF0000").
 */
@property(nonatomic, strong) NSString *cancelColor;

/**
 The text of the confirm button.
 Maximum length is 4 characters.
 */
@property(nonatomic, strong) NSString *confirmText;

/**
 The text color of the confirm button.
 Must be a hex format color string (e.g., "#00FF00").
 */
@property(nonatomic, strong) NSString *confirmColor;

/**
 Whether to show an input field (editable text box) in the modal dialog.
 When set to YES, users can input text.
 */
@property(nonatomic, assign) BOOL editable;

/**
 The placeholder text to display when the input field is empty.
 Only applicable when editable is set to YES.
 */
@property(nonatomic, strong) NSString *placeholderText;

@end

方法声明 ​

objectivec
/**
 Displays a modal dialog box (alert/prompt) to the user.
 @param stateHandle The state handle object that manages the operation state and callbacks.
 @param options The options configuration for the modal dialog (e.g., title, content, confirm button, cancel button, show input field).
 */
- (void)showModal:(id<SUDOPStateHandle>)stateHandle
          options:(SUDOPShowModalOptions *)options;

参数说明 ​

SUDOPShowModalOptions ​

参数类型是否必填说明
titleNSString *否弹窗标题文本。
contentNSString *否弹窗正文内容。
showCancelBOOL否是否显示取消按钮。设置为 YES 时,会同时展示取消按钮和确认按钮。
cancelTextNSString *否取消按钮文案,最大长度为 4 个字符。
cancelColorNSString *否取消按钮文字颜色,需为十六进制颜色字符串,例如 #FF0000。
confirmTextNSString *否确认按钮文案,最大长度为 4 个字符。
confirmColorNSString *否确认按钮文字颜色,需为十六进制颜色字符串,例如 #00FF00。
editableBOOL否是否展示输入框。设置为 YES 时,用户可以在弹窗中输入文本。
placeholderTextNSString *否输入框占位提示文本,仅在 editable = YES 时生效。

方法参数 ​

参数类型是否必填说明
stateHandleid<SUDOPStateHandle>是状态句柄对象,用于管理当前操作状态及回调。
optionsSUDOPShowModalOptions *是Modal 弹窗展示配置对象,包含标题、内容、按钮、输入框等配置。

使用示例 ​

展示普通提示弹窗 ​

objectivec
id<SUDOPStateHandle> stateHandle = self.stateHandle;

SUDOPShowModalOptions *options = [[SUDOPShowModalOptions alloc] init];
options.title = @"提示";
options.content = @"操作已完成";
options.showCancel = NO;
options.confirmText = @"知道了";
options.confirmColor = @"#007AFF";

[self showModal:stateHandle options:options];

展示确认弹窗 ​

objectivec
SUDOPShowModalOptions *options = [[SUDOPShowModalOptions alloc] init];
options.title = @"确认删除";
options.content = @"删除后数据将无法恢复,是否继续?";
options.showCancel = YES;
options.cancelText = @"取消";
options.cancelColor = @"#666666";
options.confirmText = @"删除";
options.confirmColor = @"#FF0000";

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

展示输入弹窗 ​

objectivec
SUDOPShowModalOptions *options = [[SUDOPShowModalOptions alloc] init];
options.title = @"修改昵称";
options.content = @"请输入新的昵称";
options.showCancel = YES;
options.cancelText = @"取消";
options.confirmText = @"确定";
options.confirmColor = @"#007AFF";
options.editable = YES;
options.placeholderText = @"请输入昵称";

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

仅展示确认按钮 ​

objectivec
SUDOPShowModalOptions *options = [[SUDOPShowModalOptions alloc] init];
options.title = @"提示";
options.content = @"当前网络不可用,请稍后重试";
options.showCancel = NO;
options.confirmText = @"确定";

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

处理流程 ​

  1. 业务侧创建 SUDOPShowModalOptions 对象。
  2. 设置弹窗标题 title 和正文内容 content。
  3. 根据需要设置是否显示取消按钮 showCancel。
  4. 根据需要配置取消按钮文案和颜色:cancelText、cancelColor。
  5. 根据需要配置确认按钮文案和颜色:confirmText、confirmColor。
  6. 如果需要用户输入内容,设置 editable = YES,并可配置 placeholderText。
  7. 调用 showModal:options: 展示弹窗。
  8. 用户点击确认、取消,或在输入框中输入内容后触发对应回调。
  9. SDK 通过 stateHandle 相关回调返回用户操作结果,具体回调数据结构以 SDK 实际实现为准。

注意事项 ​

  • stateHandle 不应为空,否则 SDK 可能无法正确管理当前操作状态或回调。
  • options 不应为空。
  • title 和 content 建议至少设置一个,否则弹窗可能缺少有效展示内容。
  • showCancel = YES 时,会展示取消按钮;showCancel = NO 时,通常只展示确认按钮。
  • cancelText 和 confirmText 最大长度为 4 个字符,超过限制时 SDK 可能截断、报错或展示异常,具体表现以 SDK 实现为准。
  • cancelColor 和 confirmColor 应使用合法的十六进制颜色字符串,例如 #FF0000、#00FF00、#007AFF。
  • editable = YES 时,弹窗会展示输入框,用户可输入文本。
  • placeholderText 仅在 editable = YES 时生效。
  • 如果 editable = NO,即使设置了 placeholderText,通常也不会展示输入框占位文案。
  • 用户点击确认或取消后的结果应通过 stateHandle 相关回调获取。
  • 该方法无同步返回值,展示结果、用户选择结果或输入内容应以 SDK 回调或状态回调为准。