Problem with navigation controller

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

Hello everybody,

I am using the navigation controller example that was explained in that link. But I have encountered a problem while trying to test the app on an Android device. In fact, when I deploy the app from a windows 7 machine, everything is working fine BUT when I use a mac to deploy THE SAME CODE, I have this error :

Uncaught ReferenceError : SubcategoryWindow is not defined.

This is what I added in the app.js file :

//require the UI components necessary to drive the test
var NavigationController = require('ui/Common/NavigationController').NavigationController,
    CategoryWindow      = require('ui/Android/CategoryWindow').CategoryWindow,
    SubcategoryWindow   = require('ui/Android/SubcategoryWindow').SubcategoryWindow,
    DetailWindow        = require('ui/Android/DetailWindow').DetailWindow;
 
//create NavigationController which will drive our simple application
var controller = new NavigationController();
and this is the callback from where the problem comes :
// TABLE EVENTLISTENER
    tableview.addEventListener('click', function(e)
    {   
        var id = e.row.category.id;
        navController.open(new SubcategoryWindow(navController, id));       
 
    });
I hope my problem is clear enough.

Thank you very much for your help !

Best,

Amine

Application type: mobile

Titanium SDK: 1.8.0.1.RC1

iPhone SDK version: 4.3

Android SDK version : 2.3.3

Device: Motorola milestone 2

Host Operating System: OSX 10.6.8

Titanium Studio: 1.0.7.201112152014

9 Answers

Hi,

Thank you Nick for your answer. I changed the SDK version in tiapp.xml, deleted the android build folder from my workspace, uninstalled the app from the device and deploy it again but unfortunately the same problem persists. Any other idea ?

Without the full code it could be difficult to figure this out but if your eventlistener is in the same context as your navcontroller declaration, you have a naming mismatch.

You define a navcontroller named 'controller' with this var controller = new NavigationController(); then you reference the controller in the eventlistener with the name 'navController' like this navController.open(new SubcategoryWindow(navController, id));

Without the full code, tough to tell if that is it or not.

Hi Ray,

Thank you for your answer. I don't think the problem is coming from the reference to the controller since the same code was deployed from another machine and was working. I think the problem is coming from the settings rather than the code. In fact, I also tested the sample application provided in this repository and I got the same error (Uncaught reference error : controller is not defined) both on the device and the android simulator. This same app works on iOS simulator (it crashes when you want to go back to the first page) but at least it doesn't display this error. Do you have any ideo about weither the SDK version (of titanium, iOS or android) affects the use of this kind of structure ? is there any different way to do things when you are using a mac station to develop an android app ?

Thank you again for your help guys .

try to change your file references by putting './' prefix, like this:

var NavigationController = require('./ui/Common/NavigationController').NavigationController,
    CategoryWindow      = require('./ui/Android/CategoryWindow').CategoryWindow,
    SubcategoryWindow   = require('./ui/Android/SubcategoryWindow').SubcategoryWindow,
    DetailWindow        = require('./ui/Android/DetailWindow').DetailWindow;

Alright,another stab in the dark,

I just used this code and had forgotten about this problem. Check the window code in your subcategory window. In the repository, the code for Testwindow.js shows:

exports.TestWindow = function(navController) {
    var win = Ti.UI.createWindow({
        title:'Window '+controller.windowStack.length,
        backgroundColor:'#fff',
        layout:'vertical'
    });
The error I was getting was because trying to set the title with controller instead of navController. Not sure if that might be causing your error.

Thank you guys for the ideas. I tried the code change that Yury proposed but it doesn't solve the problem. I am testing right now just the simple application proposed in the repository

var NavigationController = require('./NavigationController').NavigationController,
    TestWindow = require('./TestWindow').TestWindow;
I also removed the call to the controller from the window title :
var win = Ti.UI.createWindow({
        title:'Window ',
        backgroundColor:'#fff',
        layout:'vertical'
    });
I can display the first window but once I click on one of the two buttons, I have the error again. The callback responsible of this error is the following :
var add = Ti.UI.createButton({
        title:'Add A New Window',
        height:'50dp',
        width:'200dp',
        top:'20dp'
    });
    add.addEventListener('click', function() {
        navController.open(new TestWindow(navController));
    });
Any other propositions ?

Hi again,

It seems that this problem was resolved in the latest releases of the SDK according to this ticket. I updated my SDK and tested again but nothing new. I also followed the steps described in this workaound also no result. Can a MacBook pro user using OS X snow leopard try the sample code in this directory and tell me weither the test worked for him/her or not ?

Thank you for your help.

— answered 1 year ago by Mohamed Amine EL AOUANE
answer permalink
1 Comment
  • Because of the changes in CommonJS the navigation controller doesn't work anymore. I was just googling about this, as I'm running in the same issue right now.

    p.s. I'm on Mac OS X Lion.

    — commented 1 year ago by Nauris Pukis

On Android try this

var NavigationController = require('/NavigationController').NavigationController,
    TestWindow = require('/TestWindow').TestWindow;
I had the issue with background images on buttons. Only with this kind of a path they were showing on Android.

And second thing. Try to create a blank new project and then copy all of your .js files where you need in that new project. I had the issue that I couldn't run my project on Android after Titanium SDK update. Looks like some configuration files where changing also.

— answered 1 year ago by Dino Bartosak
answer permalink
1 Comment
  • Thnx Dino for the hints, I did what you suggested but the error is still popping up. I think it is smth related to the mac version of the SDK !!

    — commented 1 year ago by Mohamed Amine EL AOUANE

Your Answer

Think you can help? Login to answer this question!