How can i Add and Remove Dynamically a view to its parent

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

Actually I have set of Images added to a view

var imagestackv=Ti.UI.createView({
                width:0,
                height:0,
                zIndex:9999
 
            })
 
imagestackv.add(ImagesViewArray)
now the imagearray changes dynamically so i have add new set of images to same view...

how can i do this ? help me

1 Answer

Because when you add new elements without removing the old, they are appended. 1 + 1 = 2 not 1. Use the remove() method of the view to remove the elements which you've already added. Just pass those elements back in to remove them.

— answered 8 months ago by Anthony Decena
answer permalink
6 Comments
  • But It Tells NSNull error when i try to remove the View

    — commented 8 months ago by sundara nataraja

  • Simple example:

    var win = Ti.UI.createWindow({
        backgroundColor:'#000'
    });
     
    var img = Ti.UI.createImageView({
        borderRadius:10,
        image:'http://mindelusions.com/img/banner.png'
    });
    img.addEventListener('click', function() {
        win.remove(img);
    });
    win.add(img);
     
    win.open();

    — commented 8 months ago by Anthony Decena

  • Still U missed out i Have array of Image views Stored in an Array...Every time i Have to Add New Array to view.. is There any other way..

    — commented 8 months ago by sundara nataraja

  • Show 3 more comments

Your Answer

Think you can help? Login to answer this question!