有没有办法以编程方式隐藏UIAlertView?实际上我在UIAlertView中添加了一个UITextField,当用户按下键盘返回键时,我想执行与"Ok"按钮相同的操作.
我希望能够在一定时间后或特定事件(即onkeypress)上使用javascript自动关闭警报框.根据我的研究,内置的alert()函数看起来不太可能.有没有办法覆盖它并控制它打开的对话框?
此外,我不希望覆盖显示隐藏的div作为警报.我需要一个实际的对话框.
我正在浏览Android 的Phonegap源代码,并尝试验证他们的notification.alert()方法只是委托给本机JavaScript alert()函数.他们的代码做了:
Notification.prototype.alert = function(message, completeCallback, title, buttonLabel) {
var _title = (title || "Alert");
var _buttonLabel = (buttonLabel || "OK");
PhoneGap.exec(completeCallback, null, "Notification", "alert", [message,_title,_buttonLabel]);
};
Run Code Online (Sandbox Code Playgroud)
在我看来像"alert"将被解释为要调用的函数的名称exec(),但是exec()正在执行:
PhoneGap.exec = function(success, fail, service, action, args) {
try {
var callbackId = service + PhoneGap.callbackId++;
if (success || fail) {
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
}
//using: ["Notification", "alert", callbackId, true]
var r = prompt(PhoneGap.stringify(args),
"gap:"+PhoneGap.stringify([service, action, callbackId, true]));
//...
} catch …Run Code Online (Sandbox Code Playgroud) javascript ×2
alert ×1
android ×1
cordova ×1
dialog ×1
dom-events ×1
iphone ×1
prompt ×1
uialertview ×1