I have been using custom events to handle data binding with titanium appcelerator using an event called RefreshComp for a given object id (unique across all objects) and attribute passing the new value. This new value could come from a push notification , an object beeing edited in the iphone app that you want to propagate to all the comps etc...
Titanium.App.fireEvent(RefreshComp, { refreshid : objectId + '-' + attribute, value : newvalue });and
function registerEvent(objectId,attribute,eventHandler){ Titanium.App.addEventListener(RefreshComp, function(e) { if((e.refreshid === (objectId + '-' + attribute))) { eventHandler(comp, e.value); } }); }and then your eventHandler function could be as simple as
function eventHandler(comp,newvalue){ comp.value = newvalue; }or more complicated (like changing background etc...)
My point is that this causes the comp to be bound to the global context causing the object not to be release. I have tried to attach custom event to the component itself but it does not work. As a result I am getting the application that is crashing with
Exception Type: EXC_BAD_ACCESS (SIGSEGV) [TiViewProxy _hasListeners:] (TiViewProxy.m:1170) [TiUITableViewCell setHighlighted:animated:] (TiUITableView.m:80)because the binding refer to a component still in memory on the IOS side but then when TiViewProxy.m calls for the parent function in _hasListeners , it is not able to find the parent in memory that does not have any associated object and the parent has been removed form the memory
I have googled and look at the git rep of appcelerator but there are no example of this.
2 Answers
Hello,
if you want to share data across your app, you should be using Ti.App properties. Check this document about this.
Just remember that you can only share simply values this way. If you want to share something more complex, you should be using a database.
Best,
Mauro
hi jean..
please try this
var win = Ti.UI.createWindow({ fullscreen:false, layout: 'vertical' }); var btn = Ti.UI.createButton({ title: 'Update This' }); var btn2 = Ti.UI.createButton({ title: 'Open New Window' }); btn2.addEventListener('click',function(e){ var win2 = Ti.UI.createWindow({ fullscreen: false }); var btn3 = Ti.UI.createButton({ title: 'Update window behind!' }); btn3.addEventListener('click',function(e){ Ti.App.fireEvent('update:this',{ title: 'Congratulations' }); }); win2.add(btn3); win2.open(); }); Ti.App.addEventListener('update:this',function(e){ btn.title = e.newTitle; }); win.add(btn); win.add(btn2); win.open();This demo will update the window behind when he click the btn3... i hope this helps.
Your Answer
Think you can help? Login to answer this question!