Skip to content

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;

@end

Method 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 ​

ParameterTypeRequiredDescription
titleNSString *NoThe dialog title text.
contentNSString *NoThe dialog body content.
showCancelBOOLNoWhether to show the cancel button. When set to YES, both the cancel button and the confirm button are displayed.
cancelTextNSString *NoThe cancel button text, with a maximum length of 4 characters.
cancelColorNSString *NoThe cancel button text color; must be a hex color string, e.g., #FF0000.
confirmTextNSString *NoThe confirm button text, with a maximum length of 4 characters.
confirmColorNSString *NoThe confirm button text color; must be a hex color string, e.g., #00FF00.
editableBOOLNoWhether to show an input field. When set to YES, the user can enter text in the dialog.
placeholderTextNSString *NoThe placeholder text for the input field; only effective when editable = YES.

Method Parameters ​

ParameterTypeRequiredDescription
stateHandleid<SUDOPStateHandle>YesThe state handle object, used to manage the current operation state and callbacks.
optionsSUDOPShowModalOptions *YesThe 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 ​

  1. The business side creates a SUDOPShowModalOptions object.
  2. Set the dialog title title and body content content.
  3. Set whether to show the cancel button showCancel as needed.
  4. Configure the cancel button text and color as needed: cancelText, cancelColor.
  5. Configure the confirm button text and color as needed: confirmText, confirmColor.
  6. If user input is needed, set editable = YES and optionally configure placeholderText.
  7. Call showModal:options: to display the dialog.
  8. The corresponding callback is triggered after the user taps confirm, cancel, or enters content in the input field.
  9. The SDK returns the user's operation result via the stateHandle related callbacks; the actual callback data structure depends on the SDK implementation.

Notes ​

  • stateHandle should not be empty; otherwise the SDK may fail to correctly manage the current operation state or callbacks.
  • options should not be empty.
  • It is recommended to set at least one of title and content; otherwise the dialog may lack effective display content.
  • When showCancel = YES, the cancel button is displayed; when showCancel = NO, typically only the confirm button is displayed.
  • The maximum length of cancelText and confirmText is 4 characters; when the limit is exceeded, the SDK may truncate, report an error, or display abnormally, depending on the SDK implementation.
  • cancelColor and confirmColor should 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.
  • placeholderText is only effective when editable = YES.
  • If editable = NO, even if placeholderText is set, the input field placeholder text is typically not displayed.
  • The result after the user taps confirm or cancel should be obtained via the stateHandle related 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.