UserGuide

Difference between revisions of "iOS Table"

From Xojo Documentation

(Created page with "__TOC__ A Table is used to display lists of data. Tables can display information in sections, can have "accessories" to indicate that more information is available. Each row o...")
 
(Data Source)
Line 94: Line 94:
  
 
== Data Source ==
 
== Data Source ==
 +
Although you can directly add rows to a Table using the AddRow methods, this is only practical for when there are a small number of rows. When you have 50 or more rows in the table you should consider using a Data Source to provide the data for the table to display. This makes much better use of the resources available on iOS.
  
 +
[[iOSTableDataSource]] is an Interface that you implement on a class that will provide the data to the Table. The table is then populated by the class so you do not have to use the Add/Insert methods.
  
 +
These are the methods of the interface that have to be implemented in a class:
 +
[[iOSTableDataSource.RowCount|RowCount]]
 +
:Returns the number of the rows in the specified section.
 +
 +
[[iOSTableDataSource.RowData|RowData]]
 +
:This method is used to create the iOSTableCellData for the specified section and row.
 +
 +
[[iOSTableDataSource.SectionCount|SectionCount]]
 +
:Returns the total number of sections.
 +
 +
[[iOSTableDataSource.SectionTitle|SectionTitle]]
 +
:Returns the title for the specified section.
 +
 +
== Usage ==
  
 
== See Also ==
 
== See Also ==

Revision as of 14:48, 8 February 2019

A Table is used to display lists of data. Tables can display information in sections, can have "accessories" to indicate that more information is available. Each row of a Table can display images and up to 2 lines of text. In addition you can customize the rows of a table to show pretty much whatever you want.

Below is a list of commonly used events, properties and methods. Refer to iOSTable in the Language Reference for the complete list.

Events

AccessoryAction

Called when the Detail accessory for a row is tapped.

Action

Called when a row is selected. You are provided the section and row that was tapped.

ActionsForRow

Use this event to set up any row actions that are available for the row.

Refreshed

Called when the user initiates a "pull-to-refresh" action.

RowAction

Called when a row action has been selected.

RowEditingStyle

Indicates the editing style for the row when the table is put into edit mode.

Properties

AllowRefresh

Enable usage of the "pull-to-refresh" action for the table.

DataSource

Use this configure a Table to gets its data from a data source class rather than populating it using the methods.

EditingEnabled

Indicates the table is currently in edit mode.

Format

Indicates how the table is displayed. There are two choices: Plain and Grouped.

SectionCount

The number of sections in the Table. Use this in conjunction with the various methods to get row counts and other information about the table.

Visible

A boolean that indicates if the Table is visible when your app runs.

Methods

AddRow, InsertRow

Adds new rows to the end or inserts rows at a specific position of the table.

AddSection, InsertSection

Add new sections to the end or inserts sections at a specific position of the table.

CreateCell

Creates new cells (of type iOSTableCellData) to display in the table.

CreateCustomCell

Creates new custom cells that are made using iOSCustomTableCell.

ReloadData, ReloadDataInSection, ReloadRow

Reloads all the data in the table, just the data for a specific section or a single row.

RemoveAll, RemoveRow, RemoveSection

Removes all rows in the table, a single row in a section or an entire section.

RowCount

The count of rows in the specified section.

RowData

Returns an instance of iOSTableCellData that contains all the information about a row in a section.

SectionTitle

Gets or sets the title of a section.

Cell Data

When working with a Table, you will need to manage its rows. The class iOSTableCellData contains information about a row in a table. To populate a table manually, you can create instances of iOSTableCellData (using iOSTable.CreateCell), set its properties and then add it to the Table. Or you can add rows using just a subset of values manually.

Use the RowData method to get the iOSTableCellData for a specific row, which you can then use or modify to change what is displayed.

Below are commonly used properties. Refer to iOSTableCellData in the Language Reference for the complete list.

Properties

AccessoryType

The type of (optional) accessory to display for the row. This uses the AccessoryTypes enumeration to choose the type of accessory: None, Disclosure, Detail, Checkmark.

DetailText

The Detail Text is smaller text that displays below the main text for the row.

Image

When an image is specified, it appears in front of the row Text.

Tag

The Tag is an Auto that can be used to store any useful, related information about the cell for retrieval later (such as a primary key to a database or an instance of a class containing additional information).

Text

The main text that is displayed for the cell row.

Data Source

Although you can directly add rows to a Table using the AddRow methods, this is only practical for when there are a small number of rows. When you have 50 or more rows in the table you should consider using a Data Source to provide the data for the table to display. This makes much better use of the resources available on iOS.

iOSTableDataSource is an Interface that you implement on a class that will provide the data to the Table. The table is then populated by the class so you do not have to use the Add/Insert methods.

These are the methods of the interface that have to be implemented in a class: RowCount

Returns the number of the rows in the specified section.

RowData

This method is used to create the iOSTableCellData for the specified section and row.

SectionCount

Returns the total number of sections.

SectionTitle

Returns the title for the specified section.

Usage

See Also

iOSTable, iOSTableCellData, iOSCustomTableCell, iOSTableRowAction classes; iOSTableDataSource, iOSTableDataSourceEditing, iOSTableDataSourceReordering interfaces; UserGuide:iOS UI topic