Search code examples
javascriptiphonetitaniumappcelerator

iphone child view inside rows on a for() statment in JS, appcelerator


I'm making an iPhone app in appcelerator where students can see their classes schedule.

I have a JSON response where it brings me the classrooms with these attributes:

  • day
  • hour
  • class
  • professor

So an example would be an array having something like this:

[monday,8:00,math,sofia heelter]

[monday,10:00,biology,andrea sulivan]

[friday,8:00,math,sofia heelter]


I receive those parameters and show them in a UITableView with this code:

   for (var i = 0; i < response.classrooms.lenght; i++)
        {
        var day= response.classrooms[i].day;
        var hour= response.classrooms[i].hour;
        var materia= response.classrooms[i].class;
        var professor= response.classrooms[i].professor;

            var row = Titanium.UI.createTableViewRow({height:'auto'});
            var post_view = Titanium.UI.createView({
                height:'auto', 
                layout:'vertical',
                top:5,
                right:5,
                bottom:5,
                left:5
            });
            var text= Titanium.UI.createLabel({
                text:text,

                top:0,
                left:0,
                bottom:15,
                height:48,
                width:300,
                font:{fontFamily:'helvetica',fontSize:20}
            });
            post_view.add(text);
            // Add the post view to the row
            row.add(post_view);
            // Give each row a class name
            row.className = "item"+i;
            // Add row to the rowData array
            rowData[i] = row;

        }

So the question is this...

How can I assign to each class (I mean the university classroom that is shown above) which is in a row to have a child?

So when I click on the rows it brings up a child view with the info regarding their classrooms. I have the info about the classroom I just want to assign a child to every row.


Solution

  • Firstly you should set hasChild property for the row view to show that row has child.

    var row = Titanium.UI.createTableViewRow({height:'auto',hasChild:true});
    

    Then you can open a new window, or view to show the details of the data and it should be handle in your tableview click event listener.