开发者

Titanium Mobile: App crashes after loading first window

I've started a new titanium mobile project (1st time!). I have a file main.js with a tab group and 2 tabs linking to two windows. My first tabs seems to load up fine but everything after that seems to crash. I can't click on a list item or fire a buttons click event. My second tab doesn't work. It's not all the time though. Half the time it's fine, the other half it crasehs. Here is my code:

app.js:

Titanium.UI.setBackgroundColor('#fff');

var main = Ti.UI.createWindow({
    url:'main_windows/main.js',
    height:Ti.Platform.displayCaps.platformHeight,
    width:Ti.Platform.displayCaps.platformWidth,
    fullscreen: true,
    navBarHidden: false
});

main.open();

main.js:

var win = Ti.UI.currentWindow;

var appointments = Titanium.UI.createWindow({});
appointments.url = 'appointments.js';

var quotes = Titanium.UI.createWindow({});
quotes.url = 'quotes.js';

var tabAppointments = Titanium.UI.createTab({  
    icon:'../KS_nav_views.png',
    title:'Appointments',
    window:appointments
});

var tabQuotes = Titanium.UI.createTab({  
    icon:'../KS_nav_views.png',
    title:'Quotes',
    window:quotes
});

// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
//  add tabs 
//
tabGroup.addTab(tabAppointments);  
tabGroup.addTab(tabQuotes);  

// open tab group
tabGroup.open();

When I launch my app the appointments window is loaded. But when I click the quotes tab or one of the list items nothing happens.

Here is my appointments.js file:

var win = Ti.UI.currentWindow;
win.backgroundColor = '#fff';   
win.title = 'Appointments';

var data = [
    {title:'Billy Jones', hasChild:true},
    {title:'Adrian Hart', hasChild:true},
    {title:'Sid Vel', hasChild:true},
    {title:'Andrew Coats', hasChild:true}
];

// create table view
var tableview = Titanium.UI.cr开发者_高级运维eateTableView({
    data:data
});

win.add(tableview);

My quotes.js file is identical to the above but with a different window title.

Like I said sometimes the every seems to work then I rebuild the code and it's not working again.

Any help most appreciated!

Billy


what about changing main.js to

var appointments = Titanium.UI.createWindow({
  url: 'appointments.js'
});

var quotes = Titanium.UI.createWindow({
  url: 'quotes.js'
});

does that help?


you do not have a click event handler on your list view, so that is why nothing is happening when you click the list.

tableview.addEventListener('click',function(e) {
       alert("clicked row"); 
});

where are all of the files located? I noticed you have some in a directory called main_windows ? make sure you have the paths set correctly when creating the windows through URLs. You check if it is a URL path problem by moving all files to the same directory and then see if it works


Try this first...

var tabAppointments = Titanium.UI.createTab({  
    icon:'/KS_nav_views.png',
    title:'Appointments',
    window:appointments
});

var tabQuotes = Titanium.UI.createTab({  
    icon:'/KS_nav_views.png',
    title:'Quotes',
    window:quotes
});

Replace your icon path to something like this and compile and check, you don't need to give the path... / would take from the root of your app...

  1. According to your statement, the code works some times and does not some times. Delete your content of Android folder inside build folder and then try to compile, this is because of some caching issue and btw which version of titanium you are using.

  2. Remove var win = Ti.UI.currentWindow; from main.js file...

Let me know if anyone of them worked, it could be any issue among them and if your issue still persists... please do comment here back.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜