Opening new Window in Tab (CommonJS Style..?)

You must Login before you can answer or comment on any questions.

Hi,

So i am trying to create a tabbed app:

Tab1 > Window 1 > Window 2 > Window 3

Tab 2 would be the same.

I have followed the template from Appcelerator Developer relations example: https://github.com/appcelerator-developer-relations/Template.Tabbed

Once I have the first window open, I want the button click to open another window.

The example is:

function ApplicationWindow(title) {
var self = Ti.UI.createWindow({
title:title,
backgroundColor:'white'
});
 
var button = Ti.UI.createButton({
height:44,
width:200,
title:L('openWindow'),
top:20
});
self.add(button);
 
button.addEventListener('click', function() {
//containingTab attribute must be set by parent tab group on
//the window for this work
self.containingTab.open(Ti.UI.createWindow({
title: L('newWindow'),
backgroundColor: 'white'
}));

This just creates and opens a New window. I want to open a window that is in another file win2.JS:

This is the code in win2.JS:

function Win2() {
    var nextWin = Ti.UI.createWindow({
        title : title,
        backgroundColor : 'white'
    });
    return nextWin;
};
 
module.exports = Win2;
This is my code to call this from the original one:
button.addEventListener('click', function() {
testWin = require('win2');
self.containingTab.open(testWin);
My attempts so far have resulted in [WARN] Exception in event callback. { on iOS.....

Not sure where it is going wrong or what to change in the code...

— asked 10 months ago by Name Surname
1 Comment
  • p.s. additional details of the error:

    ERROR] Invalid type passed to function. expected: TiWindowProxy, was: KrollCallback in -[TiUITabProxy open:] (TiUITabProxy.m:254)

    Steve.

    — commented 10 months ago by Name Surname

1 Answer

Accepted Answer

You appear to be passing a function to the tab to open not a window object.

— answered 10 months ago by Stephen Feather
answer permalink
11 Comments
  • module.exports = Win2; <- Win2 is a function

    testWin = require('win2'); <- testWin is now a function

    — commented 10 months ago by Stephen Feather

  • self.containingTab.open(testWin()); <- That might ought to return your window object.

    — commented 10 months ago by Stephen Feather

  • Or:

    TestWin = require('win2');
    testWin = TestWin();
    self.containingTab.open(testWin);
    In your code you never actually ran the function.

    — commented 10 months ago by Stephen Feather

  • Show 8 more comments

Your Answer

Think you can help? Login to answer this question!