Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to change the source of an image in a TableViewRow with name ?

Hey,

I am working on a first application on iPhone, so sometimes I meet problem. Today I would like to change the image source of some image (imageRead) whish are in view, whish are in a TableView. I think to give a name of my TableViewRow and access to image that it contains, but I don't know how to do… I am sorry for my bad English, I am French :-P

Thank you for your help !

(my code sample to explain)


var rows=[];
for(var i=0;i<items.length;i++) {
    var row=Titanium.UI.createTableViewRow({
        className:'item',
        hasChild:false,
        height:68,
        name:'item'+items[i].id,
        id_item:items[i].id,
        url:'item.js'
    });
    var view=Titanium.UI.createView({
        width:320,
        height:68
    });
    var labelText=Titanium.UI.createLabel({
        text:items[i].text,
        left:12,
        top:12,
        height:28,
        width:296
    });
    var imageRead =  Titanium.UI.createImageView({
        image:'images/read.png',
        width:8,
        height:8,
        top:48,
        left:left
    });
    view.add(labelText);
    view.add(imageRead);
    row.add(view);
    rows.push(row);
}
var tableView=Titanium.UI.createTableView({
    data:rows,
    scrollable:true
});

For exemple I would like to change the imageRead source of the TableViewRow whish is named 'item1', what is the synthax, I would like something as like : tableView.getIndexByName('item1').child(imageRead).image = 'images/unread.png'; … ?

— asked October 3rd 2010 by MILLET Alexandre
  • getindexbyname
  • image
  • iphone
0 Comments

2 Answers

  • Accepted Answer

    If you know the row no. you can use the following:


    tblRow.children[X].image = 'images/newImg.png';

    Where X = the row number -1 (Indexing)

    — answered October 4th 2010 by Steve Clarke
    permalink
    1 Comment
    • This doesn't works even for 4.0 RC
      How could appcelerator introduce 4.0 RC sdk (so proudly) when this simple thing they cannot fix?

      — commented May 5th 2015 by Omar Hassan
  • I have tested this but it's negative…

    tableView.getIndexByName('item1').children[0].children[1].image = 'images/unread.png';
    
    — answered October 3rd 2010 by MILLET Alexandre
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.