Modal view Help!

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

Hi Wonder if someone can help me, I am trying to create a basic structure of an app that will have one home screen/view with 9 buttons on then each button will open a subsection or new window with various subsections, id like to use a modal view for each section/button and table views for drilling down.

Is this possible?

As Im struggling at the moment with understanding the structure;

initial window - 9 buttons

each button will open a new modal window over the initial window and a close button to close the modal window to return to the first window, is this correct?

Im having problems in getting sub content to open in the modal window

5 Answers

I can get a table view to open in the initial modal window but not any other sub pages

1) create the mainWindow, 2) create and add 9 buttons to mainWindow 3) for all 9 views, create separate js files 4) In the button click event handler, create window as a modal window, and open it as below.

(i)app.js

var button1 = Ti.UI.createButton ({title:'option 1', top:10, height:40});
button1.addEventListener('click', function(e){
        var win1 = Ti.UI.createWindow(url:'win1.js', fullScreen:false);
        win1.open();
});
Ti.UI.currentWindow.add(button1);
 
 
var button2 = Ti.UI.createButton ({title:'option 2', top:60, height:40});
button2.addEventListener('click', function(e){
        var win2 = Ti.UI.createWindow(url:'win2.js', fullScreen:false);
        win2.open();
});
Ti.UI.currentWindow.add(button2);
(ii)win1.js
var lbl = Ti.UI.createLabel({text:'window1', top:10, height: 40});
Ti.UI.currentWindow.add(lbl);
 
var btn = Ti.UI.createButton({title:'close window', top: 100, height:40});
btn.addEventListener('click', function(e){
        Ti.UI.currentWindow.close();
});
Ti.UI.currentWindow.add(btn);

(iii)win2.js

var lbl = Ti.UI.createLabel({text:'window2', top:10, height: 40});
Ti.UI.currentWindow.add(lbl);
 
var btn = Ti.UI.createButton({title:'close window', top: 100, height:40});
btn.addEventListener('click', function(e){
        Ti.UI.currentWindow.close();
});
Ti.UI.currentWindow.add(btn);

Thanks for the example, but what I'm having trouble doing is opening a tableview and subcontexts in a modal window, for example, from a button I want to open a modal view which opens a .js file that is a table view, and then another and another etc..

I hope the below code answers your question. you should also create a js for each row (like lists.js, search.js, etc as in the below example). Also let me know is this what you were asking for.

(ii)win1.js

var lbl = Ti.UI.createLabel({text:'window1', top:10, height: 40});
Ti.UI.currentWindow.add(lbl);
 
var btn = Ti.UI.createButton({title:'close window', top: 100, height:40});
btn.addEventListener('click', function(e){
        Ti.UI.currentWindow.close();
});
Ti.UI.currentWindow.add(btn);
 
var table = Ti.UI.createTableView({
    top: 150,
    borderWidth: 2,
    separatorColor: '#000'
});
 
var tableRows = [
{ id: 1, color:'#000', title: "Navigator Filters", hasChild: true, myPage: 'navigatorFilters.js' }, 
{id: 2, color: '#000', title: "Lists", hasChild: true, myPage: 'lists.js' }, 
{id: 3, color: '#000', title: "Search", hasChild: true, myPage: 'search.js' }, 
{id: 4, color: '#000', title: "Add Company", myPage: 'dummyPage.js' },
{ id: 5, color: '#000', title: "Add Individual",  myPage: 'dummyPage.js'}];
 
 
table.data = tableRows;
table.addEventListener('click', function(e) {
    var window5 = Ti.UI.createWindow({
        url: e.row.myPage,
        title: e.row.title,
        fullscreen: false,
        navBarHidden: true,
        backgroundColor: '#fff'
    });
    window5.open();
});
Ti.UI.currentWindow.add(table);

Your Answer

Think you can help? Login to answer this question!