我有一個導航組用於登錄。如果用戶登錄成功,那麼應用程序關閉導航組(具有navGroup.close,我認爲這會被銷燬)並創建一個選項卡組。當用戶註銷標籤組關閉並且導航組被重新創建時。問題是facebook登錄按鈕(它在導航組上)是第一次創建導航組,但第二次執行「登錄」監聽器2次和3次時間等等。 下面是一個簡化的代碼,生成此錯誤:Titanium問題與Facebook登錄按鈕和導航組
app.js
Ti.App.Properties.setString("fbAccess","login");
Ti.Facebook.appid = 'xxxxxxxxxx';
Ti.Facebook.permissions = ['publish_stream','offline_access','email'];
//Ti.Facebook.forceDialogAuth = false;
Ti.include('preLogin.js');
loginFBC.js
Ti.Facebook.addEventListener('login', function(e) {
Ti.API.info("inside login");
if ((e.success) && (Ti.App.Properties.getString("fbAccess")=="login")) {
Ti.API.info("inside if");
navGroup.close();
Ti.include('preLogin.js');
}});
preLogin.js
var buttonLoginFB = Titanium.UI.createButton({
top: "90%",
width: "70%",
height: "12%"});
var preLoginWin = Titanium.UI.createWindow({
titleImage:'/icons/logoForBar.png',
title:"Back",
backgroundColor:'#fff',
barColor:'00aeef',
});
var buttonLogin = Titanium.UI.createButton({
title: 'Login',
top: "30%",
width: "70%",
height: "12%",
opacity:1
});
var buttonRegister = Titanium.UI.createButton({
title: 'Register',
top: "60%",
width: "70%",
height: "12%",
opacity:1
});
var navGroup = Ti.UI.iPhone.createNavigationGroup({
window:preLoginWin
});
preLoginWin.add(buttonLogin,buttonRegister,buttonLoginFB);
var main = Ti.UI.createWindow();
main.add(navGroup);
main.open();
Ti.include('/loginFBC.js');
//include the preLoginC.js that holds the code for the buttons listeners
Ti.include('/preLoginC.js');
和preLoginC.js
buttonLoginFB.addEventListener("click", function(e) {
Ti.API.info("button");
Ti.Facebook.logout();
Ti.Facebook.appid = 'xxxxxxxxxxx';
Ti.Facebook.permissions = ['publish_stream','offline_access','email'];
//Ti.Facebook.forceDialogAuth = false;
Ti.Facebook.authorize();
});
你找到解決這個問題的方法 – Dev 2014-03-20 10:53:24