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