First, my English is very poor :)
I am using "navigation controller". I have various .js. My idea is: 1- app.js call Principal.js. 2- Principal call Materias.js 3- Materias.js call Unidades.js 4- Unidades.js call ... 5- ....
1 and 2 work fine. 3 don't work fine when a row is clicked.
Error message: Title: Runtime error Location: [20,16] ui/Materias.js Message: Uncaught TypeError: Cannot call method 'open' of undefined Source: navController.open(new Unidades(this.navController));
Location: [20,16] ui/Materias.js is the line: navController.open(new Unidades(this.navController));
I need Help :) simply i want navigate between various windows.
Code:
app.js
var NavigationController = require('NavigationController').NavigationController, Principal = require('ui/Principal').Principal; //create NavigationController which will drive our simple application var controller = new NavigationController(); //open initial window controller.open(new Principal(this.controller));Materias.js
exports.Materias = function(navController){ var win = Titanium.UI.createWindow({title:'Materias'}); // array de materias var tbl_materias = [ {title:'Algoritmos y Complejidad'}, {title:'Programación Orientada a Objetos'}, {title:'Base de Datos'}]; var tabla = Titanium.UI.createTableView({data:tbl_materias}); win.add(tabla); var Unidades = require('Unidades').Unidades; tabla.addEventListener('click',function(){navController.open(new Unidades(this.navController)); }); return win; }Principal.js
exports.Principal = function(navController) { // this sets the background color of the master UIView (when there are no windows/tab groups on it) Titanium.UI.setBackgroundColor('#000'); var win = Titanium.UI.createWindow({title:'Acceso', height:'auto', layout:'vertical'}); var usuarioLabel = Titanium.UI.createLabel({ text:'Usuario', textAlign:'center', width:'auto' }); win.add(usuarioLabel); var usuarioText = Titanium.UI.createTextField({ width:200, height:30 }) win.add(usuarioText); var passLabel = Titanium.UI.createLabel({ text:'Contraseña', textAlign:'center', width:'auto' }); win.add(passLabel); var passText = Titanium.UI.createTextField({ width:200, height:30 }) win.add(passText); var ingresarBtn = Titanium.UI.createButton({ title:'Ingresar' }) win.add(ingresarBtn); var Materias = require('Materias').Materias; ingresarBtn.addEventListener('click', function() {navController.open(new Materias(this.navController));}); return win; }
Unidades.js
exports.Unidades = function(navController){ var win = Titanium.UI.createWindow({ title:'datos Unidad'}); // array de unidades var tbl_unidades = [{title:'Unidad 1'}, {title:'Unidad 2'}, {title:'Unidad 3'}]; var tabla = Titanium.UI.createTableView({ data:tbl_unidades }); win.add(tabla); var Materias = require('Materias').Materias; var ingresarBtn = Titanium.UI.createButton({title:'Ingresar'}) return win; }NavigationController.js
exports.NavigationController = function() { this.windowStack = []; }; exports.NavigationController.prototype.open = function(/*Ti.UI.Window*/windowToOpen) { //add the window to the stack of windows managed by the controller this.windowStack.push(windowToOpen); //grab a copy of the current nav controller for use in the callback var that = this; windowToOpen.addEventListener('close', function() { that.windowStack.pop(); }); //hack - setting this property ensures the window is "heavyweight" (associated with an Android activity) windowToOpen.navBarHidden = windowToOpen.navBarHidden || false; //This is the first window if(this.windowStack.length === 1) { if(Ti.Platform.osname === 'android') { windowToOpen.exitOnClose = true; windowToOpen.open(); } else { this.navGroup = Ti.UI.iPhone.createNavigationGroup({ window : windowToOpen }); var containerWindow = Ti.UI.createWindow(); containerWindow.add(this.navGroup); containerWindow.open(); } } //All subsequent windows else { if(Ti.Platform.osname === 'android') { windowToOpen.open(); } else { this.navGroup.open(windowToOpen); } } }; //go back to the initial window of the NavigationController exports.NavigationController.prototype.home = function() { //store a copy of all the current windows on the stack var windows = this.windowStack.concat([]); for(var i = 1, l = windows.length; i < l; i++) { (this.navGroup) ? this.navGroup.close(windows[i]) : windows[i].close(); } this.windowStack = [this.windowStack[0]]; //reset stack };
2 Answers
Accepted Answer
i dont see you returning anything when you create your NavigationController?
exports.NavigationController = function() { this.windowStack = []; // I ADDED THIS return this; };

Your Answer
Think you can help? Login to answer this question!