对话操作不起作用。

我创建了一个对话框,想在用户按下对话框中的 OK 按钮时调用一个函数。但似乎在点击 OK 按钮时该函数没有被调用。以下是我的代码

local alert = native.showAlert( "TapNTrack", "You Lost",  "OK", onComplete )

local function onComplete(event)
    print("oncomplete");
    if "clicked" == event.action then --1
      local i = event.index --2
      if i == 1 then
       gotoLevels()
       end --2
     end-- 1
 end
点赞
用户1979583
用户1979583

尝试这个:

本地函数 onComplete(事件)
  如果 "clicked" == 事件.action then
    变量 i = 事件.index
    如果 1 == i then
      打印("OK")
    elseif 2 == i then
      打印("Cancel")
    end
  end
end

本地警告 = native.showAlert( "标题", "信息", { "OK", "Cancel" }, onComplete )

继续编写代码................ :)

2014-08-20 09:10:44