我无法从一个窗口导航到另一个窗口

发布于 2024-11-02 08:46:46 字数 3182 浏览 2 评论 0原文

我想从 Login.js 导航到 home.js,以便任何帮助我的人。

//app.js

var win = Titanium.UI.currentWindow;

var tabbar = Ti.UI.createTabGroup({
    title:"Login"
    });

var mainwin = Ti.UI.createWindow({
    url:"Login/login.js"
    });
var signupwin = Ti.UI.createWindow({
    url:"Login/Home.js"
    });

var tabLogin = Ti.UI.createTab({
    title:"Login",
    window:mainwin
    });

var tabsignup = Ti.UI.createTab({
    title:"SignUp",
    window:signupwin
    });

var nav = Titanium.UI.iPhone.createNavigationGroup({
    window:mainwin
    });


tabbar.addTab(tabLogin);
tabbar.addTab(tabsignup);    
tabbar.open({
    transition:Titanium.UI.iPhone.AnimationStyle.CURL_UP
  });
//-------------------------------------------------------
//Login.js

//Ti.include('Homescreen/HomeScreen.js');

var win = Ti.UI.currentWindow;
win.title="Login";

var win1 = Titanium.UI.createWindow({ 
        title:'first window',
        backgroundColor:'#fff'
    });

var lbluser = Ti.UI.createLabel({
        text:"UserName",
        width: 60,
        height: 32,
        left: 10,
        font:{fontcolor:"blue",fontsize:12},
        top: 10
    });

win.add(lbluser);

var username = Titanium.UI.createTextField({
    color:'#336699',
    top:10,
    left:50,
    width:250,
    height:40,
    hintText:'Username',
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(username);

var lblpass = Ti.UI.createLabel({
        text:"Password",
        width: 60,
        height: 32,
        left: 10,
        top: 50,
        font:{fontcolor:"white",fontsize:12}
    });

win.add(lblpass);
var password = Titanium.UI.createTextField({
    color:'#336699',
    top:60,
    left:50,
    width:250,
    height:40,
    hintText:'Password',
    passwordMask:true,
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    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:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
});
win.add(loginBtn);


/*
 Login Button Click Event
*/



loginBtn.addEventListener('click',function(e)
{
    if (username.value == 'Bimal' && password.value == 'Pass')
    { 
      alert("ok");
       var home = Ti.UI.createWindow({
          title:"Home Screen",
          url:'Home.js',
          _parent:win,
          nav:win.nav,
          rootWindow:win.rootWindow
        });
        win.open(home);
    }
    else
    {
        alert("Username/Password are required");
    }
});


win.open();

//-----------------------------------------------
//Home.js

var win = Titanium.UI.currentWindow;

win.title = "Home Screen";
var username = Titanium.UI.createTextField({
    color:'#336699',
    top:10,
    left:50,
    width:300,
    height:40,
    hintText:'Username',
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(username);

I want to navigate from Login.js to home.js so anyone who help me for this.

//app.js

var win = Titanium.UI.currentWindow;

var tabbar = Ti.UI.createTabGroup({
    title:"Login"
    });

var mainwin = Ti.UI.createWindow({
    url:"Login/login.js"
    });
var signupwin = Ti.UI.createWindow({
    url:"Login/Home.js"
    });

var tabLogin = Ti.UI.createTab({
    title:"Login",
    window:mainwin
    });

var tabsignup = Ti.UI.createTab({
    title:"SignUp",
    window:signupwin
    });

var nav = Titanium.UI.iPhone.createNavigationGroup({
    window:mainwin
    });


tabbar.addTab(tabLogin);
tabbar.addTab(tabsignup);    
tabbar.open({
    transition:Titanium.UI.iPhone.AnimationStyle.CURL_UP
  });
//-------------------------------------------------------
//Login.js

//Ti.include('Homescreen/HomeScreen.js');

var win = Ti.UI.currentWindow;
win.title="Login";

var win1 = Titanium.UI.createWindow({ 
        title:'first window',
        backgroundColor:'#fff'
    });

var lbluser = Ti.UI.createLabel({
        text:"UserName",
        width: 60,
        height: 32,
        left: 10,
        font:{fontcolor:"blue",fontsize:12},
        top: 10
    });

win.add(lbluser);

var username = Titanium.UI.createTextField({
    color:'#336699',
    top:10,
    left:50,
    width:250,
    height:40,
    hintText:'Username',
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(username);

var lblpass = Ti.UI.createLabel({
        text:"Password",
        width: 60,
        height: 32,
        left: 10,
        top: 50,
        font:{fontcolor:"white",fontsize:12}
    });

win.add(lblpass);
var password = Titanium.UI.createTextField({
    color:'#336699',
    top:60,
    left:50,
    width:250,
    height:40,
    hintText:'Password',
    passwordMask:true,
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    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:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
});
win.add(loginBtn);


/*
 Login Button Click Event
*/



loginBtn.addEventListener('click',function(e)
{
    if (username.value == 'Bimal' && password.value == 'Pass')
    { 
      alert("ok");
       var home = Ti.UI.createWindow({
          title:"Home Screen",
          url:'Home.js',
          _parent:win,
          nav:win.nav,
          rootWindow:win.rootWindow
        });
        win.open(home);
    }
    else
    {
        alert("Username/Password are required");
    }
});


win.open();

//-----------------------------------------------
//Home.js

var win = Titanium.UI.currentWindow;

win.title = "Home Screen";
var username = Titanium.UI.createTextField({
    color:'#336699',
    top:10,
    left:50,
    width:300,
    height:40,
    hintText:'Username',
    keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(username);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你另情深 2024-11-09 08:46:46

您应该能够使用正确的索引调用 setActiveTab。

例如,如果您将以下按钮代码放入 login.js 中,则按下按钮时应将焦点设置到主页选项卡。

var win = Ti.UI.currentWindow;
var tabGroup = win.tabGroup;
var b1 = Ti.UI.createButton({
    title : 'Press Me',
    left : 10, top : 100, right : 10, height : 40
});

b1.addEventListener('click', function(e) {
   tabGroup.setActiveTab(1);
});

win.add(b1);

更多相关示例可在此处 https:// github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/tab_groups.js

You should be able to just call setActiveTab using the correct index.

For example if you place the below button code into login.js it should set the focus to the home tab when the button is pressed.

var win = Ti.UI.currentWindow;
var tabGroup = win.tabGroup;
var b1 = Ti.UI.createButton({
    title : 'Press Me',
    left : 10, top : 100, right : 10, height : 40
});

b1.addEventListener('click', function(e) {
   tabGroup.setActiveTab(1);
});

win.add(b1);

More examples of this are available here https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/tab_groups.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文