如何在 Corona 和 Lua 中使用“id = tostring(i)”

我最近看到了像这样的东西

if(ebasRating_Arr[i] == 0) then
        radioButton_0 = widget.newSwitch {
            left = 565,
            style = "radio",
            initialSwitchState = true,
            id = tostring(i),
            width = 60,
            height = 60,
            onPress = setEBASRating0
        }
        radioGroup:insert( radioButton_0 )

        radioButton_1 = widget.newSwitch {
            style = "radio",
            id = tostring(i),
            initialSwitchState = false,
            width = 60,
            height = 60,
            onPress = setEBASRating1
        }
        radioGroup:insert( radioButton_1 )

注意第6行和第13行的“id = tostring(i)”。所以我正在尝试使用 id = tostring(i) ,想查找它的含义。有人能告诉我它真正的含义吗?那么我问题的第二部分是我怎样能在我的代码中使用像id = tostring(i)这样的东西

 local madrs = display.newGroup()
local function textListener( event )

if ( event.phase == "began" ) then

elseif ( event.phase == "ended" or event.phase == "submitted" ) then
    -- 输出“defaultField”中的结果文本

print( event.target.text )

elseif ( event.phase == "editing" ) then
    print( event.newCharacters )
    print( event.oldText )
    print( event.startPosition )
    print( event.text )
    end
end
点赞
用户9217577
用户9217577

你在使用的_for_循环中的_i_是一个数字。按钮的id应该是字符串格式,这样corona sdk才能将其作为场景等事物的名称进行识别。例如:

   composer.gotoScene("level"..tostring(event.target.id),{effect="fade"});

上面的代码会跳转到一个名为level1的场景,如果按钮的id是1。它不应该是整数或浮点数,而应该是字符串,这样corona sdk才能将其视为场景的名称。

我不理解你的问题,也没学过单选按钮的相关内容。但是,让我分享一下我知道的内容...假设你想知道radioButton_0的id并将其转换为数字。代码如下:

print(radioButton_0.id); --> 输出一个字符串(0)--
print(tonumber(radioButton_0.id));--> 输出一个数字(0)

我不了解单选按钮。如果你告诉我你上面代码的目的(应用程序),我可以帮忙。

2018-01-15 03:06:15