【问题标题】:titanium focus event fire multiple times on ios钛焦点事件在ios上多次触发
【发布时间】:2016-01-27 19:23:29
【问题描述】:

我正在通过钛 VGA 5.0.2 开发一个 ios 应用程序。我想刷新标签上的表格视图:

win.addEventListener('focus', function (e) {
     alert('Got Focus');
     load_tableview();        });

我在模拟器 iphone5s 9.1 上运行此代码。但这是多次火灾。警报不断出现在屏幕上。

【问题讨论】:

  • 上面的事件监听器在哪里注册?可能它应该注册多次。
  • 这是因为您显示的是alert。在 Titan for iOS 中,警报也是一个窗口,每次您解除警报时,win 都会获得焦点。尝试将alert 更改为Ti.API.info,它只会打印一次'Got Focus'

标签: ios focus titanium refresh tableview


【解决方案1】:

您可以避免多次 tableview 加载,如下所示

Var isFocussed = false; // Global variable to the file.
win.addEventListener('focus', function (e) {
 if(!isFocussed){
 load_tableview(); // will refresh only once
 isFocussed = true;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    相关资源
    最近更新 更多