I have a UIWebView and I want to update it's content from time to time. But when I update a content I got white background while data is loading (data include html with few JavaScripts inside). Is there any way to do it without delay?
I thought about next solution: I have 2 webViews (webView and backgroundWebView). When I need to update webView I just make a request to backgroundWebView, wait until data loaded and replace webView with backgrounWebView's content. But I do not find any solution how to replace it's content
Any advice? Thanks
Try this...
initially in viewWillAppear make UIWebView hidden and then use webview delegate method as webViewDidFinishLoad. In this webview delegate method make your UIWebView visible.
For example
-(void)viewWillAppear:(BOOL)animated
{
webView.hidden=YES;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
webView.hidden=NO;
}
You can also use UIView with any colour or UIImageView behind your UIWebView. so when your UIWebview is getting loading then it will hide and you will see its behind UIView or UIImageview
You can have dummy UIView as a placeholder and put UIWebView inside the UIView with the same size as the UIView, and replace the UIWebView using removeFromSuperview/addSubView whenever needed.
I think you're on the right track with having 2 UIWebViews, but instead of trying to pass the HTML contents of the background view to the foreground view, you should wait for the second webview to finish loading and then move it on top of the first web view with bringToFront:.
Related
I have added a UIWebView along with some labels inside UIScrollView (using StoryBoards) by adding it as a subview and then setting the ScrollView height to show all the html content of WebView that is loaded in it using loadHtmlString.
The links in the html content are not working. A little searching revealed that Apple does not recommend putting UIWebView inside UIScrollView to avoid unexpected behaviour. But as i also have to add labels and other stuff other than the UIWebView, so i have to embed them inside UIScrollView.
Is there any way I can make the links work in the html content without violating and Apple's recommendation?
There is no reason to put a UIWebView inside a ScrollView. UIWebView will scroll and zoom and pan the content properly as is. It is sort of redundant unless you have some other layout reasons for example combining it with some other views.
The correct way to add your labels is to add them to a UIViewController or NavigationController and have them positioned around the UIWebView and to also add the UIWebView to that as well.
I have one webview that fits fullscreen and loads an html file. Then another html file is loaded and I would like to apply transition between those files. Possible? Switch between two views that contains another webview is not an option due to any other reasons. Thank you.
You may insert a UIWebView inside a UIScrollView. Then when you have to load the new page, you create another UIWebView and its x will be the width of the current UIWebView, then addSubview the new UIWebView to the scrollview, and update the scrollview contentSize. Then call the method scrollRectToVisible:animated of scrollview to the frame of the new web view, this do the transition.
In addition, if you don't want to back to the previous page, you may destroy the previous UIWebview and reset the contentSize of the scrollview as it was initially.
How "another html file is loaded"? By events in the first webpage?
If you are writing the html pages you could use jQuery mobile transition?
See here
Even if you are not writing the html pages you might be able to inject javascript for this.
How would one get the contentOffset or similar information about a UIScrollView while the user is still scrolling? For example if I wanted to place an image as a header right above the content of a UIWebView, without the image being part of the WebView's scrollView, but have it update while the user scrolls, not just jumping to the position after they let go. How could I go about doing this?
In iOS 5, the UIWebView has a scrollView property which is the UIScrollView responsible for handling the scrolling. Prior to iOS 5 you can search the UIWebView's subviews property for the subview using [subview isKindOfClass:[UIScrollView class]].
Once you have the UIScrollView, you can then set its delegate property. In the delegate you can then respond to the scrollViewDidScroll: message when the user scrolls, and update the position/contents of your header view.
Added: 29/2/2012 - In order to preserve the UIWebView's functionality, you will need to forward your intercepted UIScrollViewDelegate methods to the UIWebView too. To do this, you can call the UIWebView at the end of all mandatory methods within the protocol and implement something like forwardInvocation: or forwardingTargetForSelector for the optional protocol methods. This will preserve your original UIWebView behavior and allow you to enhance it with your own logic.
Why can't you just put the header as a separate view above the UIWebView? Why does it have to be a subview?
I have a horizontal UIScrollView that contains UIButtons (though it could be any object). I would like to only download images for these buttons as the user scrolls and they are seen. I would also like an activityindicator running on each button while the images are downloading. Here's what I've tried with results:
Check content offset of uiscrollview and download images for visible buttons. Problem: issues getting activity view shown within subclassed UIButton and not desired usability since images are only downloaded once scrolling stops.
Add subviews (not buttons) to the UIScrollview hoping to use the view's ViewController to initiate a downloaded on viewDidAppear. Problem: viewDidAppear never seems to get called (because I am using addSubView?).
I've seen other apps that do this kind of loading but need some guidance on the typical set-up. Ebay's app is a great example. All items have a default image until the item comes into view, then an activityindicator runs and the items unique image is downloaded.
Thanks for assistance.
Without actually trying it out, here's my idea:
You can use the UIScrollViewDelegate method scrollViewDidScroll: to find out when your scroll view finished scrolling and then use [UIScrollView contentOffset] to determine which part of the scroll view is visible and (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view to determine the button's position within the visible part of the scroll view. Have a method that checks if the button has had its image loaded yet and if not, load it and refresh the view if necessary.
Most such apps are using a UITableView, not a plain scroll view. Joe Hewitt's Three20 framework has a TTImageView class that can do lazy image loading and is pretty well suited to this kind of use.
I'm displaying a UISearchBar at the top of a UIWebView for entering information that I use to display content in the UIWebView. Is there a way to attach the UISearchBar (or perhaps a UITextField?) to the UIWebView "header" so that when the user scrolls down on the webview the UISearchBar also scrolls out of view and the full window is able to display text?
If this is not possible, how else could I accomplish this while still using the UIWebView for it's inherent text formatting capabilities?
You may try containing the UIWebView and UISearchBar within a UIScrollView. That is, create a controller that has the main view as a UIScrollView and then add in the UISearchBar and UIWebView as subviews. If you want custom behavior when you're scrolling you may have to override the event callbacks for scrolling. I haven't tried this but in theory you could have it so that when you get a scroll down and the UISearchBar is in view, you hide it up to a certain # of pixels until the UISearchBar is hidden. Afterwards you forward the scroll request to the UIWebView so it can deal with things. Basically have a middleman that delegates the scroll events as necessary.