UIWebview not showing editview on first tap - ios

This is an issue with iOS9 and later.
On the load of application I select a word in UIWebview but theres no editview popup showing copy, share, define etc options on first tap.
From next selection after the tap it works fine.
even the -(BOOL)canPerformAction:(SEL)action withSender:(id)sender delegate returns NO for all options on first tap and select
Also when you select a word and scroll it up off the screen and try to select other word. the view scrolls up/down on its own and a worng word will be selected(View displaces itself by an offset of the amount the selected word is scrolled off the screen).
Pulling my hair to get this fixed. Any help would be appreciated
its simple code
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view becomeFirstResponder];
NSString *urlAddress = #"https://en.wikipedia.org/wiki/Main_Page";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_myWebView loadRequest:requestObj];
}

UIWebview has many bugs and is not memory efficient .
Replaced UIWebview with WKWebView on apple's recommendation and it fixed all the bugs.

Related

IOS/Objective-C: Force UIWebView to reload

I have a screen that shows a web view. However, I allow people to cycle through different web views by updating an object. When I load the first page, the web view loads fine. However, when I try to update the page from the new object in viewwillappear, while other elements such as a title that goes above the webview load fine, the web view does not refresh.
//in viewWillAppear
self.title = self.file.imageDescript;//The title loads fine
NSString *urlBase = #"https://www.~com/images/";
NSString * imagename = self.file.imagename;
NSString *url = [NSString stringWithFormat:#"%#%#",urlBase,imagename];
NSURL *realUrl = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:realUrl];
[webView loadRequest:request];
I have tried various versions of setNeedsDisplay and also applied these to subviews of the web view without success as in this method:
- (void) forceRedrawInWebView:(UIWebView*)webView {
NSArray *views = webView.scrollView.subviews;
for(int i = 0; i<views.count; i++){
UIView *view = views[i];
//if([NSStringFromClass([view class]) isEqualToString:#"UIWebBrowserView"]){
[view setNeedsDisplayInRect:webView.bounds]; // Webkit Repaint, usually fast
[view setNeedsLayout]; // Webkit Relayout (slower than repaint)
// Causes redraw & relayout of *entire* UIWebView, onscreen and off, usually intensive
[view setNeedsDisplay];
[view setNeedsLayout];
// break; // glass in case of if statement (thanks Jake)
//}
}
}
I have read in one SO answer that since IOS8.2, refresh of UIWebView no longer works (as WKWebView) has replaced it. I would switch to WKWebView except that it is not supported in storyboards, apparently, and I have a bunch of stuff going on in the storyboard.
Note: this has nothing to do with refreshing the same web url because content has changed on a server. It has to do with loading an entirely different web url in the UIWebView
Can anyone suggest way to fix this?

Obj C UIWebview go button click action

Here I'm loading one uiwebview in coding and show one pdf file successfully. In that pdf file have one Textfield and Go button. when i click the textfield means the keyboard will open will go button in down. Show in screen shot. I need that uiwebveiw that loaded pdf textfield keyboard go button action. help me. thanks advance
[textField setReturnKeyType:UIReturnKeyGo];
- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
NSString *urlAddress = textField.text;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL];
[WebView loadRequest:aRequest];
}

Web View Orientation iOs

I am using a ModalViewController to open an web view in my app.
Inside my class, i've this piece of code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = #"address";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
}
Well, in my app the interface orientation is always in portrait mode. But, when i start the web view, a video will show up, and i need to change my interface to every kind of orientations.
Observation: I don't want to change on the class that i am running the modal view controller. I just want to change the orientation inside my video.

Another (!) Activity Indicator Issue

Well, after reading a bunch of SO posts on this issue, I still can't fix problems with my activity indicator. This indicator is in a view in a tab under the control of its own view controller. It has a view with a UIWebView which loads a local html page just fine. The view is loaded with initWithNibName and then awakeFromNib. Here's the part I think is relevant:
#implementation HelpViewController
#synthesize webView = _webView;
#synthesize back = _back;
#synthesize forward = _forward;
#synthesize aI = _aI;
- (void) viewDidLoad {
_aI = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[_aI stopAnimating];
// Now add the web view
NSString *filePath = [[NSBundle mainBundle]
pathForResource:#"Help"
ofType:#"html"];
[self.view addSubview:_webView];
_webView.delegate = self;
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
[_webView loadRequest:request];
[super viewDidLoad];
}
-(void) webViewDidStartLoad:(UIWebView *)webView {
[_aI startAnimating];
_back.enabled = NO;
_forward.enabled = NO;
}
-(void) webViewDidFinishLoad:(UIWebView *)webView {
[_aI stopAnimating];
if (webView.canGoBack) {
_back.enabled = YES;
_back.highlighted = YES;
}
if (webView.canGoForward) {
_forward.enabled = YES;
_forward.highlighted = YES;
}
}
The navigation buttons work fine. The activity indicator was placed in the nib, but in the main view, not on/over/under the webView. In the attributes, I have Hides When Stopped checked. If I check Animating the indicator is always visible and animated, no matter how I navigate through the UIWebView.. If I uncheck Animating, Hidden is automatically checked for me. In this case, the indicator never shows up. So it's either always on or always off.
I've read quite a bit about cases where you need to have the indicator on a different thread. I'm not sure, but I don't think that applies here (I load a local html page but allow users to navigate off and then back to the local page). But, I seem to have some disconnect; perhaps it is the fact that the indicator is in the main view but the pages are in the webView? Or I'm not calling things in the right methods. Or who knows... Thanks for any help!
You overwrite _aI in your viewDidLoad and never place it in your view hierarchy, so the object you are sending the messages to is never visible and the activity indicator placed in interface build will never change its state, so thats why its either always animating or hidden.

iPad SplitView detailView default load

I have an iPad split-view app. The detailview is a webview. In which method, can I get a default page loaded when the app launch before the user clicks on an item in the table view?
IN detailviewcotroller.h , create outlet as follows,
IBOutlet UIWebView *WEBVIEW;
connect outlet in xib by drag n droping uiwebview control.
In your detailviewcontroller.m's viewdidload method u can write as follows-
NSString *str=#"yr default webpage link here";
NSURL *url=[NSURL URLWithString:str];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
[WEBVIEW loadRequest:req];
Just a good advice, by creating Outlets, when you synthesize do:
#synthesize webView = _webView;
and use :
[_webView loadRequest:req];
for loading your request.

Resources