Ti.App.fireEvent triggering many times for iPhone application.
Hello all,
Am developing a iPhone application in which upon click of a button in webview(html) it calls the function in my temp.js. Everything works fine, but the function is trigged 2times.
I've gone through other Q&A and to be more specific i found the solution for android with this ticket
http://developer.appcelerator.com/question/11211/webview-fireevent
My titanium version is 1.3.0 and the iPhone sdks is 3.1
Can you please suggest a solution for the same in iPhone?
Thanks in advance.
4 Answers
-
Accepted Answer
Sathishkumar
The ticket you have referenced is very old, and things have moved on since then. In fact the bug described was fixed.
The only way to answer this is if you provide some stripped-down working code (simple code that works without further modification) that demonstrates the situation you describe.
I assure you, your problems would be answered so much quicker every single time if you are able to bear this advice in mind.
I could speculate that the behaviour you have observed is the normal effect of event bubbling, but without code that would be a total guess.
-
@Hal H
Thanks for your advice and the following describes a prototype of my code snippet.
1. tmlogin.html - local file available in Resources Folder.
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>LoginForm</title> <script type="text/javascript"> function buttonOkClick() { var un; var ps; var a; var b; un = (document.getElementById("inputUserName")); ps = (document.getElementById("inputPassword")); a = un.value; b = ps.value; Ti.App.fireEvent('info',{a:a,b:b}); } </script> </head> <body> <input type="text" id="inputUserName" /> <input type="password" id="inputPassword" /> <input type="button" value="Log In" onclick="buttonOkClick()"/> </body> </html>
2. getvalue.js - local file available in Resources Folder.
var win = Titanium.UI.currentWindow; var username; var password; var data = [{title:'CPF Cloud Login', hasChild:true, url:'tmlogin.html'}]; var tableview = Titanium.UI.createTableView({ data:data, }); tableview.addEventListener('click', function(e) { var rowdata = e.rowData; var w = Ti.UI.createWindow(); var webview = Ti.UI.createWebView(); webview.url = rowdata.url; w.add(webview); win.tab.open(w); Ti.App.addEventListener('info', function(e){ username = e.a; password = e.b; alert(username); alert(password); invoker(); calls further implementation using XHR SOAP }); }); win.add(tableview);
Here my alerts and invoker() functions are triggered twice and hence the every further step inside invoker() is happening twice. Can you please suggest a solution for this problem. I've gone thro most of the Q&A regarding the same issue but not able to find the answer.
-
@Hal H. Thanks for your help. I used Ti.API.info() for displaying my results and everything works fine.
Also i figured out that multiple or too many use of alert() will crash the application because it was not the fault of fire event which is crashing my application but too many usage of alert() once i removed all those alert() it worked fine. Instead usage of Ti.API.info() is better. :-)
-
@Hal H. Thanks for your help. I used Ti.API.info() for displaying my results and everything works fine.
Also i figured out that multiple or too many use of alert() will crash the application because it was not the fault of fire event which is crashing my application but too many usage of alert() once i removed all those alert() it worked fine. Instead usage of Ti.API.info() is better. :-)