Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 多文本字段的侦听器_Lua_Coronasdk - Fatal编程技术网

Lua 多文本字段的侦听器

Lua 多文本字段的侦听器,lua,coronasdk,Lua,Coronasdk,我正在尝试从多个字段调用文本字段侦听器,如本页所示 当用户开始在输入字段中写入内容时,通常会调用处理程序函数,但不会调用位于处理程序中的闭包 login.lua文件如下所示: local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- Forward declerations local userNameField -- TextField Listener local func

我正在尝试从多个字段调用文本字段侦听器,如本页所示

当用户开始在输入字段中写入内容时,通常会调用处理程序函数,但不会调用位于处理程序中的闭包

login.lua文件如下所示:

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

-- Forward declerations    
local userNameField

-- TextField Listener
local function fieldHandler( getObj )

     print( "This message is showing up :) " )

    -- Use Lua closure in order to access the TextField object
    return function( event )

        print( "This message is not showing up :( There is something wrong here!!!" )   

        if ( "began" == event.phase ) then
            -- This is the "keyboard has appeared" event
            getObj().text = ""
            getObj():setTextColor( 0, 0, 0, 255 )

        elseif ( "ended" == event.phase ) then
        -- This event is called when the user stops editing a field:
        -- for example, when they touch a different field or keyboard focus goes away

            print( "Text entered = " .. tostring( getObj().text ) ) -- display the text entered
        elseif ( "submitted" == event.phase ) then
        -- This event occurs when the user presses the "return" key
        -- (if available) on the onscreen keyboard
        -- Hide keyboard
           native.setKeyboardFocus( nil )
        end
    end -- "return function()" 
end

local function userNameFieldHandler( event )
   local myfunc =  fieldHandler( function() return userNameField end ) -- passes the text field object
end

-- Called when the scene's view does not exist:
function scene:createScene( event )
    local group = self.view

-- Create our Text Field
    userNameField = native.newTextField( display.contentWidth  * 0.1, display.contentHeight  * 0.5, display.contentWidth * 0.8, display.contentHeight * 0.08)

    userNameField:addEventListener( "userInput", userNameFieldHandler )
    userNameField.font = native.newFont( native.systemFontBold, 22 )
    userNameField.text = "User Name"
    userNameField:setTextColor( 0, 0, 0, 12 )
end

请帮忙…

我不知道科罗纳,但你的代码有点奇怪

userNameFieldHandler
没有什么作用,它只是创建一个调用
fieldHandler
的处理程序,并将其存储在一个从未使用过的本地(
myfunc
)中。你确定你不是这个意思:

local function userNameFieldHandler( event )
   local myfunc =  fieldHandler( 
      function() return userNameField end ) -- passes the text field object
   return myfunc --<<<<--- added return
end
userNameField:addEventListener( "userInput", userNameFieldHandler() )