showModal
Overview
showModal:options: displays a modal dialog to the user, supporting configuration of the title, content, confirm button, cancel button, and input field.
This interface is commonly used to display confirmation prompts, warning messages, secondary user confirmation, or simple text input scenarios, such as "Confirm deletion" or "Enter nickname".
Type Declaration
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;
@endMethod Declaration
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;Parameters
SUDOPShowModalOptions
| Parameter | Type | Required | Description |
|---|---|---|---|
title | NSString * | No | The dialog title text. |
content | NSString * | No | The dialog body content. |
showCancel | BOOL | No | Whether to show the cancel button. When set to YES, both the cancel button and the confirm button are displayed. |
cancelText | NSString * | No | The cancel button text, with a maximum length of 4 characters. |
cancelColor | NSString * | No | The cancel button text color; must be a hex color string, e.g., #FF0000. |
confirmText | NSString * | No | The confirm button text, with a maximum length of 4 characters. |
confirmColor | NSString * | No | The confirm button text color; must be a hex color string, e.g., #00FF00. |
editable | BOOL | No | Whether to show an input field. When set to YES, the user can enter text in the dialog. |
placeholderText | NSString * | No | The placeholder text for the input field; only effective when editable = YES. |
Method Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
stateHandle | id<SUDOPStateHandle> | Yes | The state handle object, used to manage the current operation state and callbacks. |
options | SUDOPShowModalOptions * | Yes | The modal dialog display configuration object, containing the title, content, buttons, input field, and other settings. |
Example
Display a normal prompt dialog
objectivec
id<SUDOPStateHandle> stateHandle = self.stateHandle;
SUDOPShowModalOptions *options = [[SUDOPShowModalOptions alloc] init];
options.title = @"Notice";
options.content = @"The operation has been completed";
options.showCancel = NO;
options.confirmText = @"OK";
options.confirmColor = @"#007AFF";
[self showModal:stateHandle options:options];Display a confirmation dialog
objectivec
SUDOPShowModalOptions *options = [[SUDOPShowModalOptions alloc] init];
options.title = @"Confirm Deletion";
options.content = @"Data cannot be recovered after deletion. Continue?";
options.showCancel = YES;
options.cancelText = @"Cancel";
options.cancelColor = @"#666666";
options.confirmText = @"Delete";
options.confirmColor = @"#FF0000";
[self showModal:self.stateHandle options:options];Display an input dialog
objectivec
SUDOPShowModalOptions *options = [[SUDOPShowModalOptions alloc] init];
options.title = @"Edit Nickname";
options.content = @"Please enter a new nickname";
options.showCancel = YES;
options.cancelText = @"Cancel";
options.confirmText = @"OK";
options.confirmColor = @"#007AFF";
options.editable = YES;
options.placeholderText = @"Please enter a nickname";
[self showModal:self.stateHandle options:options];Display only the confirm button
objectivec
SUDOPShowModalOptions *options = [[SUDOPShowModalOptions alloc] init];
options.title = @"Notice";
options.content = @"The network is currently unavailable. Please try again later";
options.showCancel = NO;
options.confirmText = @"OK";
[self showModal:self.stateHandle options:options];Process Flow
- The business side creates a
SUDOPShowModalOptionsobject. - Set the dialog title
titleand body contentcontent. - Set whether to show the cancel button
showCancelas needed. - Configure the cancel button text and color as needed:
cancelText,cancelColor. - Configure the confirm button text and color as needed:
confirmText,confirmColor. - If user input is needed, set
editable = YESand optionally configureplaceholderText. - Call
showModal:options:to display the dialog. - The corresponding callback is triggered after the user taps confirm, cancel, or enters content in the input field.
- The SDK returns the user's operation result via the
stateHandlerelated callbacks; the actual callback data structure depends on the SDK implementation.
Notes
stateHandleshould not be empty; otherwise the SDK may fail to correctly manage the current operation state or callbacks.optionsshould not be empty.- It is recommended to set at least one of
titleandcontent; otherwise the dialog may lack effective display content. - When
showCancel = YES, the cancel button is displayed; whenshowCancel = NO, typically only the confirm button is displayed. - The maximum length of
cancelTextandconfirmTextis4characters; when the limit is exceeded, the SDK may truncate, report an error, or display abnormally, depending on the SDK implementation. cancelColorandconfirmColorshould use valid hex color strings, e.g.,#FF0000,#00FF00,#007AFF.- When
editable = YES, the dialog displays an input field where the user can enter text. placeholderTextis only effective wheneditable = YES.- If
editable = NO, even ifplaceholderTextis set, the input field placeholder text is typically not displayed. - The result after the user taps confirm or cancel should be obtained via the
stateHandlerelated callbacks. - This method has no synchronous return value; the display result, user selection result, or input content should be based on the SDK callback or state callback.
