1
在我的鈦手機項目上遇到麻煩。下面的代碼顯示了一個登錄頁面,當點擊登錄按鈕時,它將把用戶重定向到tabGroup(tab1和tab2)。登錄重定向到製表組
// this sets the background color of the master
// UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#fff');
// create tab group
var tabGroup;
var win = Titanium.UI.createWindow({
title:'TabViewLogin',
tabBarHidden:true,
});
var username = Titanium.UI.createTextField({
color:'#336699',
top:10,
left:10,
width:300,
height:40,
hintText:'Username',
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(username);
var password = Titanium.UI.createTextField({
color:'#336699',
top:60,
left:10,
width:300,
height:40,
hintText:'Password',
passwordMask:true,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(password);
var loginBtn = Titanium.UI.createButton({
title:'Login',
top:110,
width:90,
height:35,
borderRadius:1,
font:{fontWeight:'bold',fontSize:14}
});
win.add(loginBtn);
win.open();
Titanium.App.addEventListener('logout', function(e) {
win.open();
tabGroup.close();
});
loginBtn.addEventListener('click',function(e)
{
if (tabGroup == undefined) {
tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});
var label1 = Titanium.UI.createLabel({
color:'#999',
text:'I am Window 1',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win1.add(label1);
//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({
title:'Tab 2',
backgroundColor:'#eee'
});
var tab2 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
title:'Tab 2',
window:win2
});
var label2 = Titanium.UI.createLabel({
color:'#999',
text:'I am Window 2',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win2.add(label2);
var button = Ti.UI.createButton({
title: "Logout",
style: Ti.UI.iPhone.SystemButtonStyle.DONE
});
button.addEventListener('click',function(e)
{
Ti.App.fireEvent('logout');
});
win1.setRightNavButton(button);
win2.setRightNavButton(button);
//
// add tabs
//
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
}
// open tab group
win.close();
tabGroup.open();
});
但現在的問題是,我需要它先用下面的代碼,重新將它們直接到tabGroup之前驗證用戶身份。
Cloud.Users.create({
email: '[email protected]',
first_name: 'test_firstname',
last_name: 'test_lastname',
password: 'test_password',
password_confirmation: 'test_password'
}, function (e) {
if (e.success) {
var user = e.users[0];
alert('Success:\n' +
'id: ' + user.id + '\n' +
'sessionId: ' + Cloud.sessionId + '\n' +
'first name: ' + user.first_name + '\n' +
'last name: ' + user.last_name);
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
感謝您的任何援助
感謝Daniula的回覆。雖然我理解Ti.APP.Properties的使用,但我的問題是;如何將用戶從登錄頁面(警告消息之後)重定向到tabGroup。任何示例代碼讓我開始將非常感激。非常感謝。 –
好的,我沒有得到。我添加了TabGroup.setActiveTab()的文檔鏈接,它可以幫助你。 – daniula