object:insertRow()

类型 函数
widget.*
修订 版本 2024.3703
关键词 表视图、列表视图、TableViewWidget、insertRow
另请参见 widget.newTableView()
TableViewWidget

概述

该函数用于将行插入 TableViewWidget 中。

语法

object:insertRow( options )

此函数需要一个参数 options,它是一个接受以下参数的表:

id (可选)

字符串. 可选标识符,分配给行。默认值是行的索引。

rowHeight (可选)

数值. 行的总高度,以像素为单位。

rowColor (可选)

. 二个 RGB+A 颜色设置表,分别用于默认状态和覆盖状态。

rowColor = { default={ 1, 1, 1 }, over={ 1, 0.5, 0, 0.2 } }
lineColor (可选)

. 定义分隔线颜色的 RGB+A 值表,假设设置了显示线条。

lineColor = { 0.5, 0.5, 0.5 }
isCategory (可选)

布尔. 如果为 true,则该行将作为类别行进行渲染。类别行“固定”在表视图的顶部,因为它会随着用户滚动而滚动,表示下面的行是该类别的部分。

params (可选)

. 可以包含与特定行相关的信息的表。然后可以通过 event.row.params 在行呈现函数中以及通过 event.target.params 在行触摸侦听器中访问(读取)此信息。

示例

-- Insert 40 rows
for i = 1, 40 do

    local isCategory = false
    local rowHeight = 36
    local rowColor = { default={ 1, 1, 1 }, over={ 1, 0.5, 0, 0.2 } }
    local lineColor = { 0.5, 0.5, 0.5 }

    -- Make some rows categories
    if ( i == 1 or i == 21 ) then
        isCategory = true
        rowHeight = 40
        rowColor = { default={ 0.8, 0.8, 0.8, 0.8 } }
        lineColor = { 1, 0, 0 }
    end

    -- Insert a row into the tableView
    tableView:insertRow(
        {
            isCategory = isCategory,
            rowHeight = rowHeight,
            rowColor = rowColor,
            lineColor = lineColor,
            params = {}  -- Include custom data in the row
        }
    )
end