loadHTMLString won't fire while UIScrollView is scrolling - iphone

I'm trying to lazy load UIWebViews inside a UIScrollView.
Every time the user scrolls, the WebViews frames are updated and new content SHOULD be loaded. And that's exactly where I'm having trouble. The repositioning works well, but the new content (local NSStrings, which are called using loadHTMLString) does not appear until I stop scrolling the ScrollView.
I've read this thread already: NSURLRequest won't fire while UIScrollView is scrolling.
Getting some inspiration from that, is there any association I could make between loadHTMLString and NSURLConnection? I know next to nothing about NSURLConnection.
If that's not possible, is there any other solution? Either halting the scroll for a while (like MobileRSS – an App Store app – does) or alternate loading methods?
Edit: My UIScrollView has paging enabled. So if I were to halt the scroll for a while, it should happen at every page. But I still don't know how to accomplish that.

Old question, but here is an answer for it.
You'll have to subclass the UIWebView and switch the run loops started at a overridden loadHTMLString:baseURL:
and switching it back after the html has been loaded (or failed to load).
Check out this project on github which gives you an example of where to override in all the right places.

Related

iPhone - How prevent an UIWebView to draw/update its content

I have some view inside wich there are an UIWebView. For performance reasons, I do not allocate the Web view on the fly, but it is set into IB and linked with a class outlet. When I do not need it, I set its hidden property to YES.
But, after having profiled my application because of performance problems, I noticed that when resizing the views containing those UIWebViews, they take a huge amount of time in :
[WebFrame(WebInternal) _drawRect:contentsOnly:]
So to prevent this, I also set their scalesPageToFit to NO, but this doesn't change anything.
I've tested deleting them from the project, and yes, the resize of the view is really much faster.
So how can I prevent the UIWebViews that are hidden to eat my process time in useless drawing work ?
Instead of hiding the UIWebView try removing it from the container view using removeFromSuperview. When you want to make it visible again add it back as a subview. This should keep the instance of the UIWebView in memory and prevent it from redrawing when it is not visible.

iOS - Force a UIWebView to load content?

I set the content of a UIWebView using loadHtmlString:. I don't add them to the UIView until they are need, but I need to know the max scroll height of each of them.
The problem is that UIWebView doesn't start loading it's data until it's added to a superView, and It's the delay of loading content that is causing this problem.
Question: Is it possible to force a UIWebView to load its content, without being added to a view?
You can add it to the view and set it's opacity to 0.01 to force the load. I've had to do this with MKMapView before.
I'd use hidden property of UIWebView - setting it to YES before view is added and clearing it to NO in webViewDidFinishLoad: should do the trick.
However, you comment to #logancautrell's answer is a bit unsettling - do you ever plan to get that many web views added to your views? I assume you know that, but just in case: depending on your possible HTML(5)/JavaScript/CSS code, you may observe severe performance hit even with a small number of web views for which iOS needs to allocate lots of resources.
If you plan to update your web views often, maybe you could benefit from UIWebView's stringByEvaluatingJavaScriptFromString: method? To some extent, the performance hit can be bearable, I think.
I suggest either pre-calculating the scroll heights somehow (not during web view load), or finding a way to display your UIViews without waiting for the scroll heights initially, and correct them later.

UIImage not load in UITableView with lazy image loading

When I scroll to new area of the UITableView with lazy image loading, then
immdietly scroll back to the old area, no matter what I do now, the new area will not show new images.
My code is based on apple lazy table view.
Till now I thought it was something with the web server, but I had cache functionality now, and all images are loaded from iphone files, so for sure there is somthing wrong in my code.
Again, the images are not shown ONLY in that case :
UITableView is loading the data
All visible cell are showing the images correctly.
If I scroll to new area, move to old area *quickly* and move back to new area the image will not load, no matter where I scroller now(only the images in the new area that I quickly scorll back from will not load)
all on other cases, the images are shown correctly.
Without seeing the some code its hard to say. If your display is tied to a callback from the NSURLConnection you might be losing your reference to the delegate.
When you scroll the cell view get repopulated with the data in the new cell. If the NSURLConnection is running outside of the cell view you might be losing the reference to it's delegate. When the NSURLConnection is completed if it doesn't have a delegate to fire the complete method then it won't get called. When you scroll to the new cell the NSURLConnection is already complete so it doesn't call the completed again and the spinner just keeps going.
I fix it. the bug was nothing to do with all above. so nothing to share and learn from.
I thought it is important for other I'll be clear about that, so no one will be confused about what I wrote earlier.
The process of checking if image already download was wrong.

UIView changes when iphone application starts from background

My iphone application has a user form under UIViewController.
When I out of application (go to background mode) and start application again some of my UIView changes its positions and sizes. (These UIViews depend on keyboard position)
Definately somewhere is my fault.
I try to figure what is going on when application starts again from background and where the UIView changes can be done.
May be you can suggest any links to read.
Thank you.
The UIViewController's viewDidLoad and viewWillAppear methods get called every time the view is dumped from memory, something that commonly happens when the app goes into the background. Depending on your code, it's possible that you're storing some position data that's not getting cleared. If that's the case, you can either:
Change your code to better fit the Model-View-Controller pattern so that the positioning code and variables are all in the controller, and you appropriately clean things up in its 'viewWillDisappearandviewDidUnload` methods (the better way), or
Clear out whatever remnants are hanging around in your application delegate's applicationWillEnterBackground method.

Uiwebview shouldloadrequest not getting called sometimes

I am using nine webviews inside a scrollview to get an infinte scrolling effect. I am loading image map inside each webviews. Now the problem is webviews are not responding sometimes for the touches, when it is a hard-touch(touch and hold). I am getting this issue when more than one webviews are visible. I have set the delegate for every webviews, I dont know why this happening.
I am loosing the selection while holding it, its grey color dissappears. This issue I am getting only in 3.2iPad device.
I need to get the shouldStartLoadWithRequest method called while each press. what i need to do?
thanks in advance,
You have to read the Apple document for UIWebview, they are clearly saying,"Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled."
check this link:- http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html
But I also do adding UIWebview to UIScrollview, But in my case the frame of a webview is same as the frame of scrollview. In this case the touchevent is properly detected.
And One issue I found in this case we can get UITapGestureRecognizer from that Uiwebviews...