【问题标题】:sharing a button variable between two files在两个文件之间共享一个按钮变量
【发布时间】:2013-10-30 15:17:08
【问题描述】:

我有一个按钮,点击它会打开一个带有额外共享功能的模式窗口。在 Android 上一切正常,但我对 iOS 有一个小问题。我可以共享一个只是数字的变量,但不能共享作为按钮的变量。以下来自主 app.js 的代码:

var shareBtn2;
var fullScore;
shareBtn2.addEventListener('singletap', function (e){

    shareBtn2.setBackgroundImage('share_pressed.png');

    var shareModal = require('shareModal');
    var shareModalView = new shareModal();
    Ti.App.myGlobalVar=shareModalView;
    win2.add(shareModalView);

    if (DJBool){
        Ti.App.fireEvent('shareModalEvent', {
              myBtn: shareBtn2,
              myPts: Math.round(fullScore)
        });
        alert('Was a DJBool');
    }

然后在我的第二个文件中,其中包含 4 个用于分享的按钮、fb、twitter、电子邮件和一个取消按钮。

Ti.App.addEventListener('shareModalEvent', function(event) {
    globalPts=event.myPts;
    globalBtn=event.myBtn;
    alert('received share modal event');
});

console.log(typeof globalPts);//outputs number
console.log(typeof globalBtn);//outputs undefined

我在第二个文件中需要这个按钮的唯一原因是如果用户按下第二个文件中的“取消按钮”,我想将我的 shareBtn 的 backgroundImage 更改为其原始状态。即

cancelBtn.addEventListener("click", function (e){
        cancelBtn.setImage('cancelShare_pink.png');
        win2.remove(Ti.App.myGlobalVar);
        globalBtn.setBackgroundImage('share.png');

    });

希望我已经清楚了。

【问题讨论】:

    标签: javascript iphone variables titanium global


    【解决方案1】:

    事实证明,您不能在事件中传递圆形 Ti.UI 对象,只能在 IOS 中传递原语(如字符串、数字),但它在 Android 上有效。最后我写了另一个自定义事件来解决这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      相关资源
      最近更新 更多