ボタン ウィジェットから onEvent リスナーを削除しようとしています。nil を onEvent 属性に割り当てようとしましたが、うまくいきませんでした。最後にこれを試しました:
buttonWidget : removeEventListener("touch", buttonWidget.onEvent)
そのようなボタンがいくつかあり、すべてのボタンのイベントリスナーが停止しました。何を指示してるんですか?1 つのボタン ウィジェットのイベント リスナーを削除するにはどうすればよいですか? ありがとう。
ボタンウィジェットを作成する方法は次のとおりです。
for i=0,2 do
for j=0,8 do
count=count+1
letterBtn[count] = widget.newButton{
id = alphabet[count],
left = 5+j*50,
top = H-160+i*50,
label = alphabet[count],
width = 45,
height = 45,
font = nil,
fontSize = 18,
labelColor = { default = {0,0,0}, over = {255,255,255}},
onEvent = btnOnEventHandler
};
end
end
後で onEvent を削除する方法を教えてください。
わかりました、Button: setEnabled(false) を試しましたが、それでも 1 つだけでなくすべてのボタンが無効になります。私はすでにあなたの2番目のアドバイスを試しましたが、同じ結果が得られます. 残りのコードをコピーしています。それを見て、何が欠けているか教えていただけますか?
local function checkLetter(e)
if(guessWord) then
for i=1, #guessWord do
local c = guessWord:sub(i,i)
if c==e.target.id then
letter[i].text = e.target.id
letterCount = letterCount +1
print("letterCount"..letterCount)
e.target:setEnabled(false)
end
end
if (letterCount == #guessWord and not hanged) then
timer.performWithDelay(500, function()
letterCount=0
rightWGuess = rightWGuess+1
for k,v in pairs(notGuessedWord) do
if v == guessWord then
notGuessedWord[k]=nil
end
end
enableButtons()
startGame() end ,1)
end
end
end
local function btnOnEventHandler(e)
if(e.phase == "began") then
checkLetter(e)
print(e.target.id)
end
return true
end