beetlebug

ztk::ios::alert

Shows an alert or an action sheet (UIAlertController) over the top screen of the window, and gives its object at once.

Light Dark
An alert of iOS over the Fruit list: the title Delete Plums?, the message Plums leave the list., and the buttons Cancel and Delete in red The same alert in the dark mode of iOS

Synopsis

ztk::ios::alert ?-title TEXT? ?-message TEXT? ?-style alert|sheet? ?-buttons LIST? ?-command SCRIPT?

Arguments

Name Type Default Meaning
-title text empty The title in bold.
-message text empty The text under the title.
-style alert, sheet alert alert shows a box in the middle of the screen. sheet shows an action sheet.
-buttons list {OK} The buttons, each one {LABEL ?STYLE?}. STYLE is default, cancel, or destructive (red).
-command script empty Runs at the global level at a tap on a button, with the label of the button appended.
buttons method Gives the labels of the buttons, in their order.
invoke INDEX method Closes the alert and runs -command, as a tap on the button INDEX does.
destroy method Frees the alert.

A tap on a button closes the alert, runs -command, and destroys the object. The alert shows over native screens and over the Tk window. An alert has no configure or cget.

Return value

The command gives the object of the alert. buttons gives a list. invoke gives an empty string.

Errors

Error When
unknown option "-X": must be -buttons, -command, -message, -style, or -title Another option.
value for "-X" missing An option with no value.
bad style "STYLE": must be alert or sheet -style has another value.
bad button style "STYLE": must be cancel, default, or destructive A button has another style.
an alert needs a button -buttons is an empty list.
no button N invoke with an index past the last button.

Platforms

Platform Works
Windows No
macOS No
Linux, Wayland No
Linux, X11 No
Web No
iOS Yes
Android No: ztk::android::alert
Headless No: the namespace does not exist.

Example

ztk::ios::alert -title "Delete Plums?" -message "Plums leave the list." \
    -buttons {{Cancel cancel} {Delete destructive}} \
    -command {apply {{label} {if {$label eq "Delete"} {puts deleted}}}}

See also