beetlebug

ztk::ios::ListScreen

Makes a screen of rows in sections (UITableView), with the rows from the methods of a subclass.

Light Dark
A list screen of iOS with the large title Fruit, the section Orchard with Apples, Pears, and Plums, and the section Berries with Cherries and Figs. Each row has a leaf symbol and a chevron The same list in the dark mode of iOS

Synopsis

ztk::ios::ListScreen new ?-title TEXT? ?-style STYLE?
$CELL configure ?OPTION VALUE ...?

Arguments

Name Type Default Meaning
-title text empty The title in the navigation bar.
-style insetGrouped, grouped, plain insetGrouped The look of the sections. Only new sets it.
-search boolean 0 1 shows a search field: under the title, or at the bottom of the screen on iOS 27. Each change of its text runs the method search.
-editing boolean 0 1 shows a handle on each row that movable allows, and the user drags the row to another place.
sections method Gives the number of sections. The default method gives 1.
rows SECTION method Gives the number of rows of a section, from 0. The default method gives 0.
title SECTION method Gives the title over a section. The default method gives an empty string: no title.
cell SECTION ROW CELL method Fills a row with $CELL configure. UIKit reuses rows, so the method sets each option that the row shows.
select SECTION ROW method Runs at a tap on a row.
actions SECTION ROW method Gives the swipe actions of a row: a list of {LABEL ?STYLE?}. STYLE destructive is red, and each other style is gray. The first action is at the right edge. The default method gives an empty list: no swipe.
swiped SECTION ROW LABEL method Runs at a tap on a swipe action, with its label.
search TEXT method Runs at each change of the text of the search field. The method keeps the rows that match and calls reload.
movable SECTION ROW method Gives 1 when the user can drag the row in the editing mode. The default method gives 0.
move FROMSECTION FROMROW TOSECTION TOROW method Runs when the user drops a row at another place. The method moves the row in its data; UIKit has moved it on the screen.
searchText method Gives the text of the search field.
invokeSearch TEXT method Puts TEXT in the search field and runs search, as typing does.
invokeMove FROMSECTION FROMROW TOSECTION TOROW method Runs move, as a drop does.
closed method Runs when the screen leaves its navigation stack, before the screen is destroyed.
reload method Asks the data source again for each row on the screen.
invoke SECTION ROW method Runs select, as a tap on the row does.
invokeAction SECTION ROW INDEX method Runs swiped for the swipe action INDEX of actions, as a tap on it does.
push, pop, navigationStack method As for a screen.
configure, cget, destroy method As for each object (ztk::ios).
-text cell option empty The main text of the row.
-detail cell option empty A second line of smaller text in a secondary color.
-symbol cell option none A symbol of SF Symbols before the text, such as folder or star.fill. An empty string shows no symbol.
-accessory cell option none The mark at the end of the row: none, disclosure (a chevron), checkmark, or detail.
-indent cell option 0 The level of indent, an integer.

UIKit calls the methods of the data source for the rows on the screen. An error in one goes to bgerror, and the list uses the default of the method.

Return value

new gives the object. The methods reload, invoke, invokeAction, invokeSearch, and invokeMove, and $CELL configure, give an empty string.

Errors

Error When
-style of a list is set by new only configure -style after new.
bad style "STYLE": must be grouped, insetGrouped, or plain -style has another value.
unknown option "-X": must be -accessory, -detail, -indent, -symbol, or -text $CELL configure has another option.
bad accessory "X": must be checkmark, detail, disclosure, or none -accessory has another value.
no symbol "NAME" of the system -symbol names no symbol of SF Symbols.
expected integer but got "X" -indent, or an argument of invoke or invokeAction, is no integer.
no cell to change: change a cell in the method cell of the list $CELL configure outside of the method cell.

Platforms

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

Example

oo::class create Fruit {
    superclass ztk::ios::ListScreen
    variable names
    constructor {} {
        set names {{Apples Pears Plums} {Cherries Figs}}
        next -title Fruit
    }
    method sections {} { llength $names }
    method rows {section} { llength [lindex $names $section] }
    method title {section} { lindex {Orchard Berries} $section }
    method cell {section row cell} {
        $cell configure -text [lindex $names $section $row] -symbol leaf -accessory disclosure
    }
}
ztk::ios::app root [ztk::ios::NavigationStack new [Fruit new]]

See also