native.cancelAlert()

类型 函数
native.*
返回值
修订版 2024.3703 版
关键字 提示、显示对象、原生对象
另请参见 native.showAlert()

概述

以编程方式取消提示框。例如,你可能希望在十秒后即使用户未点击它也会自动消失的弹出提示。在这种情况下,可在计时器结束时调用此函数。

语法

native.cancelAlert( alert )
alert (必需)

表格. 要取消的提示,从 native.showAlert() 返回。

示例

标准
local function onComplete( event )
    if event.action == "clicked" then
        local i = event.index
        if i == 1 then
            -- Do nothing; dialog will simply dismiss
        elseif i == 2 then
            -- Open URL if "Learn More" (the 2nd button) was clicked
            system.openURL( "https://solar2d.com/" )
        end
    end
end
 
-- Show alert with two buttons
local alert = native.showAlert( "Solar2D", "Dream. Build. Ship.", { "OK", "Learn More" }, onComplete )
 
-- Dismisses "alert" after 10 seconds if user has not responded
local function cancelMyAlert()
    native.cancelAlert( alert )
end
 
timer.performWithDelay( 10000, cancelMyAlert )
取消并显示新的提示
-- Handler that gets notified when the alert closes
local function onComplete( event )
   if event.action == "clicked" then
        local i = event.index
        if i == 1 then
            -- Do nothing; dialog will simply dismiss
        elseif i == 2 then
            -- Open URL if "Learn More" (second button) was clicked
            system.openURL( "https://solar2d.com/" )
        end
    end
end

local alert

if ( alert ~= nil ) then
    native.cancelAlert( alert )
    alert = nil
end

local function showAlert()
    alert = native.showAlert( "Solar2D", "Dream. Build. Ship.", { "OK", "Learn More" }, onComplete )
end

timer.performWithDelay( 10, showAlert )