How to clear the content of editable UIWebview without dismissing the keyboard - iphone

I have a UIWebView with the content editable set to true. Now if tap on the UIWebView a cursor appears on the UIWebView and the keyboard pops up. Now I am able to write some thing in this editable UIWebView.
My problem is that when I try to clear the content of this editable UIWebView, the content gets cleared but the keyboard is also gets dismissed. I want to clear the content of the editable UIWebView without dismissing the keyboard.
I am using following code to clear the editable UIWebView.
[self.webView loadHTMLString:#"" baseURL:nil];
Any help would be appreciated.

You could try and clear the webview through javascript:
[webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML = '';"];
Reloading the web view will set it into a default state where it is not currently being edited and the keyboard is hidden. With the above snippet, you are going to directly change the content of the web view without affecting its state.

Related

Is there any way to update UIWebView without getting white background?

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:.

UIKeyboard pushing UIWEBVIEW

Currently the way ios handles input fields in the uiwebviews is by pushing the uiwebview up when u tap on the input field in a uiwebview. Sometimes, the uiwebview goes outside the page. I was wondering how the whole things work? My parentviewcontroller doesn't have any scrollview inside etc.. but yet it pushes the uiwebview up.
Any idea how I can prevent the keyboard from pushing the uiwebview up. How does it know by how much it needs to push up. I added a method to get the information about the keybaord when it shows up and the size of the keyboard which is returned is 1024px for the height which is really weird.
Thanks.

iOS transition between two html files on a uiwebview

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.

Editing HTML in UIWebView

I am loading an HTML file in my UIWebView and displaying it in my app. Now I want to all the user to edit this html in the UIWebView real time (i.e. when he is viewing it in the UIWebView). To put it in a different way; Does UIWebView allow editing it's HTML content like a UITextField or UITextView does?
No. It doesn't allow HTML editing.
The closest solution I think of is getting the HTML content and put it in a UITextView but that wouldn't be very user-friendly.
How about split the screen into two view. Web view and text view. Edit text in the text view. When user tap a 'done' button apply the changed text to the web view. Or you can use timer to continuously update web view with the current content of text view.

UIWebView with UISearchBar for searching

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.