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 remove removeEventListener from tableView...

Hi guys.

I am using this eventListener for the row click (from kitchensink sample). When I refresh list the event is created again thus firing two times. I want to remove it with removeEventListener, so only current event stays. How can I modify the function below. I've tried several things, but non worked.


tableview_hitro.addEventListener('click',function()

{
    var w = Titanium.UI.createWindow({title:lower_label.text});
    var label2 = Titanium.UI.createWebView({html:'<html><body></body></html>'});

    w.add(label2);

    w.open({modal:true});

});
— asked May 10th 2010 by Miha Jakovac
  • android
  • removeeventlistener
  • tableview
0 Comments

4 Answers

  • I wrote the solution. I run this function below on every refresh to clear the data and even. It works for now :)

    //global var
    var tableview_event = null
    
    function tableview_clearData(table_view)
    {
       for (var c = 0;c < table_view.data.length;c++)
       {
        table_view.data[c].remove();
        try
        {        table_view.data[c].removeEventListener('click',tableview_event);
        }
        catch(ex){}
       }
    }
    
    function refresh()
    {
      tableview_clearData(table_view);
      tableview_event = table_view.addEventListener('click',function(e)
      {
      }
    }
    
    — answered May 11th 2010 by Miha Jakovac
    permalink
    2 Comments
    • I looked so long for a solution, but this finally workes.
      Thank you!!

      — commented March 18th 2013 by Marco Huppertz
    • It worked till Titanium SDK 3.1.

      Now it throws following errors:
      nativeLocation = "-[TiUITableViewSectionProxy remove:] (TiUITableViewSectionProxy.m:95)";
      nativeReason = "expected: TiUITableViewRowProxy, was: (null)";

      It would be great, If someone has an idea for that.
      Thanks

      — commented May 3rd 2013 by Marco Huppertz
  • 
    var the_ev = tableview_hitro.addEventLi.....
    
    
    blah blah
    
    
    tableview_hitro.removeEventListener('click', the_ev);
    

    is this working?

    — answered May 10th 2010 by Dan Tamas
    permalink
    0 Comments
  • Hello.

    Thank you for your answer Daniel. This way it does not work, because first it creates an event and secondly destroys it. I've also tried creating global counter to cancel the remove for the first time, but this works just partially, because as soon as new item is there it leaves the old data..

    Is there any way to globally clear the data (and also the events from the tableview?

    Thanks in advance.

    — answered May 11th 2010 by Miha Jakovac
    permalink
    0 Comments
  • add and remove don´t retrun anything….its type "void"….

    but i can´t understand why i have to use function name to remove?!

    if i add with addEventListener('click',function(e) {
    i can not remove it…why?

    really anoing..

    — answered June 15th 2010 by Christian Brauwers
    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.