object:selectValue()

类型 函数
widget.*
返回值
版本 2024.3703 版
关键字 widget、picker、PickerWheelWidget、selectValue
另请参见 widget.newPickerWheel()
PickerWheelWidget

概述

PickerWheelWidget 的特定列中选择特定行。另外,可选择直接/立即捕捉到该行,而无需通过默认的滚动动作。

注意事项

语法

object:selectValue( targetColumn, targetIndex [, snapToIndex] )
targetColumn (必填)

数字. 表示要操作的列的整数,范围从 1PickerWheelWidget 中的列总数(从左到右).

targetIndex (必填)

数字. 表示要在指定列(targetColumn)中选择的行索引的整数。这必须是范围从 1 至列中的总行数的有效行索引。

snapToIndex (可选)

布尔值. 如果为 true,则将立即选择指定的 column+row(无滚动动作)。默认值为 false

示例

local widget = require( "widget" )

-- Set up the picker wheel columns
local columnData = 
{ 
    { 
        align = "left",
        width = 124,
        labelPadding = 20,
        startIndex = 2,
        labels = { "Hoodie", "Short Sleeve", "Long Sleeve", "Sweatshirt" }
    },
    {
        align = "left",
        width = 96,
        labelPadding = 10,
        startIndex = 1,
        labels = { "Dark Grey", "White", "Black", "Orange" }
    },
    {
        align = "left",
        width = 60,
        labelPadding = 10,
        startIndex = 3,
        labels = { "S", "M", "L", "XL", "XXL" }
    }
}

-- Create the widget
local pickerWheel = widget.newPickerWheel(
{
    x = display.contentCenterX,
    top = display.contentHeight - 160,
    columns = columnData,
    style = "resizable",
    width = 280,
    rowHeight = 32,
    fontSize = 14
})

-- Select the third row in the first column
pickerWheel:selectValue( 1, 3 )

-- After 4000 milliseconds (4 seconds), select the fourth row in the second column
timer.performWithDelay( 4000, function() pickerWheel:selectValue( 2, 4 ); end )