How to remove fireEvent?

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

I have a fireEvent listener. I want to remove this listener, but my listener is nickname function. I add

Ti.App.removeEventListener('drawBaseMapHandler');
It will show
[WARN] Exception in event callback. {
    line = 36;
    message = "*** -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]";
    sourceId = 141614720;
}
how to remove fireevent.

my code is

myWebView.addEventListener('load',function(e){ myWebView.evalJS("Ti.App.addEventListener('drawBaseMapHandler',function(e){" +"var gObj=gChart(e.strUrl);"+"drawBaseMap(gObj);"+"})");
            Ti.App.removeEventListener('drawBaseMapHandler');
});

— asked 10 months ago by Chang YuanYu
3 Comments
  • When you call eventlistner, set a variable value like drawBaseMapHandler_var and check inside the block if it's value is set then remove property.

    myWebView.addEventListener('load',function(e){ myWebView.evalJS("Ti.App.addEventListener('drawBaseMapHandler',function(e){" +"var gObj=gChart(e.strUrl);"+"drawBaseMap(gObj);"+"})");
        if(Ti.App.Properties.hasProperty('drawBaseMapHandler_var')){
        Ti.App.removeEventListener('drawBaseMapHandler');
        }
    });

    — commented 10 months ago by Abdus Sattar

  • Hi Chang YuanYu,

    from where you fire drawBaseMapHandler event?.

    — commented 10 months ago by Nitin Chavda

  • HI ,Nitin Chavda, I fire drawBaseMapHandler event in other js, that place is in callback function.

    — commented 10 months ago by Chang YuanYu

2 Answers

Hi Chang,

Ivan in the link explained it in a fairly superb manner. I think instead of evaluating the JS code through webview you should add that code directly like this:

myWebView.addEventListener('load',function(e){ 
    var eventId = Ti.App.addEventListener('drawBaseMapHandler',function(g){ 
                              var gObj=gChart(g.strUrl);
                              drawBaseMap(gObj);
                   });
 
     Ti.App.removeEventListener('drawBaseMapHandler', eventId);
});
Please do let me know as to why you want your listener to be added using myWebView.evalJS() function

Your Answer

Think you can help? Login to answer this question!