【问题标题】:Moving one window to another in titanium在钛合金中移动一个窗口到另一个窗口
【发布时间】:2013-10-11 11:04:21
【问题描述】:

我的 app.js

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// create tab group
var tabGroup = Titanium.UI.createTabGroup();


//
// create base UI tab and root window
//
var homeWindow = Titanium.UI.createWindow({  
    backgroundColor:'#fff',
    url:'home.js',
    backgroundImage:'appImage/background.png',
    navBarHidden:true
});
var homeTab = Titanium.UI.createTab({  
    icon:'appImage/home.png',
    size:{height:10,width:10},
    title:'Home',
    backgroundColor:'#999',
    window:homeWindow
});



//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff',
    url:'win2.js'
});
var tab2 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 2',
    window:win2
});

//win2.add(label2);

// win3
var win3 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff',
    url:'win3.js'
});
var tab3 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 3',
    window:win3
});


//win3.add(label2);


// win4

var win4 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff',
    url:'win4.js'
});
var tab4 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 4',
    window:win4
});

//win5

var win5 = Titanium.UI.createWindow({  
    title:'Tab 5',
    backgroundColor:'#fff',
    url:'win5.js'
});
var tab5 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 5',
    window:win5
});

//win6

var win6 = Titanium.UI.createWindow({  
    title:'Tab 6',
    backgroundColor:'#fff',
    url:'win6.js'
});
var tab6 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 6',
    window:win6
});


//
//  add tabs
//
tabGroup.addTab(homeTab);  
tabGroup.addTab(tab2);
tabGroup.addTab(tab3);
tabGroup.addTab(tab4);  
tabGroup.addTab(tab5);  
//tabGroup.addTab(tab6);



// open tab group
tabGroup.open();

我的家.js

var txtLogoImage = Ti.UI.createImageView({
  image:'appImage/txtLogo.png',
  height:30,
  width:170,
  top:15,

});

var loginButton = Ti.UI.createButton({
    title: 'Login',
    //image:'appImage/atm.png',
    backgroumdImage:'appImage/buttonbg.png',
    top: 90,
    height:30,
  width:170,

});

loginButton.addEventListener('click',function(event){
    //How can I go to the win2???
});

var atmLocatorButton = Ti.UI.createButton({
    title: 'ATM Locator',
    top: 130,
    height:30,
    width:170
});

var branchLocatorButton = Ti.UI.createButton({
    title: 'Branch Locator',
    top: 170,
    height:30,
    width:170
});


var cityTouchLogoImage = Ti.UI.createImageView({
    image:'appImage/citytouchlogo.png',
    top:250,
    left:'150',
    height:100,
    widht:250
});

Ti.UI.currentWindow.add(txtLogoImage);
Ti.UI.currentWindow.add(loginButton);
Ti.UI.currentWindow.add(atmLocatorButton);
Ti.UI.currentWindow.add(branchLocatorButton);
Ti.UI.currentWindow.add(cityTouchLogoImage);

当有人点击登录按钮时,我想移动win2(Tab2)。我该怎么做?

【问题讨论】:

  • 很抱歉打扰您 Atish,但请考虑批准我的编辑以使标题更有意义。谢谢!

标签: javascript titanium


【解决方案1】:

如果您想从任何地方切换标签,请将其添加到定义 tabGroup 的位置,在本例中为您的 app.js:

Ti.App.addEventListener('app:gotoTab', function(e) {
    tabGroup.setActiveTab(e.tab);
});

将此添加到您的登录事件监听器:

// tab index starts with 0, so 0 is your first tab
Ti.App.fireEvent('app:gotoTab', { tab: 1 });

【讨论】:

  • 在可能的情况下 gotoTab 的值是多少?
  • 在您的情况下,它应该是 1,就像在答案中一样,因为选项卡索引是从零开始的。
  • Ti.App.fireEvent('app:1', { tab: 1 });是吗??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
  • 2013-11-04
相关资源
最近更新 更多