PDA

View Full Version : Click events stop after stringByEvaluatingJavaScriptFromString to UIWebView




bitblit
Nov 8, 2008, 08:26 AM
I have a Dashcode developed webapp that I ported to a UIWebView object in Xcode. I have a menu in native obj-C that the user can touch, to send messages via stringByEvaluatingJavaScriptFromString to the webapp. The webapp responds accordingly and changes the view of my stackLayout with setCurrentView. But it usually then stops responding to user touches. I can still scroll up and down. I can still navigate with the native obj-C nav bar, but nothing from my javascript onClick events. I confirmed as best I can that the events are no longer firing and that its not a javascript code error on my part. It sometimes even still works briefly, but then stops working again after a few seconds. I suspect that's just lag in whatever disabled it.

I monitored the isUserActionEnabled property from the UIWebView, and it does not change when the error occurs. When the user touches a button on the native code side, it sends an stringByEvaluatingJavaScriptFromString command to execute a javascript function called navigationHomeCall(). When I debug this in Dashcode, and call the function in the Evaluator Window, it does the same thing. It stops the javascript from receiving anymore events. However, if I keep calling my navigationHomeCall, navigationBackCall, and navigationForwardCall functions from in the Evaluator Window, the events will eventually start working again. Sometimes it takes 1 or 2 calls before it works. Sometimes more. But once it starts working, another call will stop it working again.

It seems that evalJS can randomly enable or disable javascript events. I looked through the javascript object model to see what, if any, properties change to cause this but the model is huge, I can only see maybe 20 properties on the screen at a time, and Dashcode keeps changing the window to the Run Log everytime I make the call to invoke the error. It makes troubleshooting very slow.

Has anybody successfully used stringByEvaluatingJavaScriptFromString and javascript events without any problems? I'm not the first one to try this, am I?



bitblit
Nov 9, 2008, 11:35 PM
I spent the last 2 days implementing a fixed navbar in html, javascript, and CSS. Incidentally, thanks for removing the location: fixed property. I much prefer writing a hundred lines of code rather than a single "location: fixed" line.

After completing the changes, we found that the bug still shows itself. I was wrong about being triggered by stringByEvaluatingJavaScriptFromString. It actually occurs when I go back to a certain view.

This is a single index.html with css, javascript, and a bunch of images. In dashcode, it has 26 views in a StackLayout. I shuffle between the views with SetCurrentView and SetCurrentViewWithTransition. In all, its 3.6 MB on disk. We monitored the memory usage and noticed before long, allocated memory grows to 42 MB. If this is how the Dashcode framework works, it is completely unacceptable. Is there a bug or am I using the StackLayout wrong?

Incidently, we temporarily got around the problem by SetCurrentView to a different view. Its not the ideal solution since now my user seems to mysteriously jump to an unrelated view and adds 2 touches where there should only be 1.