类型 函数 库 widget.* 修订 版本 2024.3703 关键词 表视图、列表视图、TableViewWidget、insertRow 另请参见 widget.newTableView() TableViewWidget
该函数用于将行插入 TableViewWidget 中。
object:insertRow( options )
此函数需要一个参数 options,它是一个接受以下参数的表:
字符串. 可选标识符,分配给行。默认值是行的索引。
数值. 行的总高度,以像素为单位。
表. 二个 RGB+A 颜色设置表,分别用于默认状态和覆盖状态。
rowColor = { default={ 1, 1, 1 }, over={ 1, 0.5, 0, 0.2 } }
表. 定义分隔线颜色的 RGB+A 值表,假设设置了显示线条。
lineColor = { 0.5, 0.5, 0.5 }
布尔. 如果为 true,则该行将作为类别行进行渲染。类别行“固定”在表视图的顶部,因为它会随着用户滚动而滚动,表示下面的行是该类别的部分。
表. 可以包含与特定行相关的信息的表。然后可以通过 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