I have a UIWebView embeded as a subview which loads an html form from the web. The problem is that when you select one of the text fields it receives the focus, but the keyboard does not display. this only happens on iOS6 if i run this app on iOS 4.3, 5.1 etc it works as expected. Any one have any advice
- (void)viewDidLoad
{
[super viewDidLoad];
webView = [[UIWebView alloc] init];
[webView setUserInteractionEnabled:YES];
[webView setScalesPageToFit:YES];
[webView setKeyboardDisplayRequiresUserAction:YES];
// load url here
NSURL *url = [NSURL URLWithString:redirectUrl];
//URL Requst Object
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
[requestObj setHTTPMethod:#"POST"];
[webView loadRequest:requestObj];
UIScrollView* sv = nil;
for(UIView* v in [webView subviews]){
if([v isKindOfClass:[UIScrollView class] ]){
sv = (UIScrollView*) v;
sv.scrollEnabled = NO;
sv.bounces = NO;
}
}
[webView setOpaque:NO];
[webView setBackgroundColor:[UIColor whiteColor]];
webView.delegate = self;
[self.view addSubview:webView];
}
You can use the answer of this question:
Some UITextfields don't respond in iOs6
You have to resingfirstresponder before presentmodalviewcontroller in the the controller where are you calling the view with the problem.
BUT, you also have to resignfirst responder in all previews controllers, that is.
In my case i go from a searchbar to a detail view, and from detail to share in facebook. The view of share in facebook wasn't showing the keyboard, and it was 'cause i wasn't resiginif first responder of search bar.
Hope it helps.
Related
We have used the below lines of code to move to the web view:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.location.hash=\'#-1\';"]];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.location.hash=\'#%#\';", index]];
but somehow this code doesn't work only in iPad. Here is how I initialised the web view:
webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView setDelegate:self];
[webView.scrollView setDelegate:self];
[webView setBackgroundColor:WHITECOLOR];
[webView setScalesPageToFit:YES];
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview: webView];
Could someone please guide me how to debug it.
In iOS11 location.hash seems to be broken, but it's a simple solution to this.
Instead using an usual combination:
location.hash = "";
location.hash = _some_hash_string_
use javascript below:
var hashElement=document.getElementsByName(_some_hash_string_)[0];
if(hashElement) {
hashElement.scrollIntoView();
} else {
// if the element is not found - scroll to top
document.documentElement.scrollIntoView();
}
I want to add a subView to this WKWebView with this content (https://www.windytv.com/?-34.816,138.608,5). so that the subView can be panning along with the webview (imagine there's landmark view being panning along), but I could do it.
I tried many ways as follows:
I add a landmarkView to different subViews of the webView, failed.
1.1 For example:
[self.webView addSubView:landmarkView];
1.2 Or:
[self.webView.scroolView addSubView:landmarkView];
1.3 Or:
[self.webView.scroolView.subViews.firstObject addSubView:landmarkView]; // In viewDidAppear
The interesting thing here is the view hierachy of WKWebsite will change in viewDidAppear. It gets more subView like "WKContentView".
Followed by 1., I try to add a gestureView to pass the gesture to move the landmarkView, failed. The action of the gesture did not procceed.
1.1. For example, I add on the super view of webView.
[self.view addSubView: baseView];
[self.baseView addSubView: webView];
self.panGestureRecognizer.cancelsTouchesInView = NO;
[webView addGestureRecognizer: self.panGestureRecognizer];
Or, I add on the subView of webView.
[self.view addSubView: webView];
[self.webView addSubView: gestureView];
gestureView.backgroundColor = [UIColor clearColor];
self.panGestureRecognizer.cancelsTouchesInView = NO;
[gestureView addGestureRecognizer: self.panGestureRecognizer];
Anyone familiar with WKWebView?
Except for UIGesture, Is there other ways to distribute a touch to many views?
If I could override the touchesBegan method in one of the subViews, it should be much easier. And I think hitTest still work only on a view.
The general
- (void)viewDidLoad
{
UIView *landmarkView = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)];
landmarkView.backgroundColor = [UIColor redColor];
NSString *path = #"https://www.windytv.com/?-37.331,145.102,7";
NSURL *url = [NSURL URLWithString:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
[self.view addSubView: self.webView];
[self.webView.scrool addSubView:landmarkView]; // This is one of the failed attempts.
}
It can be solved by adding a panGesture with this delegate method.
The trick is introduced here:
UIPanGestureRecognizer on MKMapView?
I'm automatically generating a NSURL based on the distance of a pan gesture on the screen (long story...). Anyways, I'm having no problem generating the URL. The URL dynamically changes, and then I have an NSTimer that repeats every second which tells a UIWebView to reload with the new URL.
However, although the URL is reported to be changing, the UIWebView will only show the first URL sent to it. I'm also monitoring the website itself, and it's receiving the first URL every second, opposed to the updated ones. My code is pretty simple right now, so I'm not sure what I did wrong? Any help would be appreciated.
In ViewController.h:
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#property float slicenumber;
#property NSURL *dynamicUrl;
In ViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *fullURL = #"http://localhost:8080/remote/slicer/slice?view=Green&orientation=Axial&scrollTo=.50&size=native&fmt=png";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
[self.webView reload];
self.webView.scrollView.scrollEnabled = NO;
self.webView.scrollView.bounces = NO;
self.slicenumber=.5;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(UpdateSlice) userInfo:nil repeats:YES];}
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self.view];
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
self.slicenumber=self.slicenumber+translation.y/350;
if (self.slicenumber<0) {
self.slicenumber=0;
}
if (self.slicenumber>1) {
self.slicenumber=1;
}
self.sliceloc.text= [NSString stringWithFormat:#"%.2f",self.slicenumber];
NSString *fullURL2 = [NSString stringWithFormat:#"http://localhost:8080/remote/slicer/slice?view=Green&orientation=Axial&scrollTo=%.2f&size=native&fmt=png",self.slicenumber];
self.dynamicUrl = [[NSURL alloc] initWithString:[fullURL2 stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSLog(#"urlString = %#",self.dynamicUrl);}
- (void)UpdateSlice {
[self.webView loadRequest:[NSURLRequest requestWithURL:self.dynamicUrl]];
[self.webView reload];}
Thanks a lot! Let me know if you need any other info.
[self.webView reload] - will reload the current page. This is probably happening before the loadRequest has finished.
Try removing this line.
Also, #joern's comment is correct; the 'event' is the user making a pan gesture. Lose the timer.
I am trying to get the activity indicator to stop animating once the view has loaded. Currently, the view has loaded but the activity indicator does not stop circulating. Here is my code:
UIWebView *elionWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 375, 579)];
[self.view addSubview:elionWebView];
elionWebView.delegate = self;
//Start the Activity Indicator
[self webViewDidStartLoad:elionWebView];
//Load Website
NSString* url = #"https://google.com/";
NSURL* nsUrl = [NSURL URLWithString:url];
NSURLRequest* request = [NSURLRequest requestWithURL:nsUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
[self webViewDidFinishLoad:elionWebView];
[elionWebView loadRequest:request];
}
-(void)webViewDidStartLoad:(UIWebView *)webView {
//Start the Activity Indicator
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityView.center = CGPointMake(187.5, 370);
[activityView startAnimating];
activityView.tag = 100;
[self.view addSubview:activityView];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[self.view viewWithTag:100].hidden = YES;
There are a few problems with your code. Firstly, NSURLRequest does not actually load the URL. There are different ways to do the download. Look at NSURLConnection for the simplest way to do a synchronous download.
Secondly, I suggest you declare your UIActivityIndicatorView as a member variable of your class rather than tagging the view.
There are UIActivityIndicatorView methods for starting and stopping animations. You should use stopAnimating to stop the animation. If you have set the property hidesWhenStopped to YES on the view, then you will get the behavior you want. If you do not want the indicator after animation has stopped, use removeFromSuperview to get rid of it.
I have a UITableView that loads content into a UIWebView like this:
//MainViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect bounds = [ [ UIScreen mainScreen ] applicationFrame ];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:bounds];
UIWebView *htmlView = [ [ UIWebView alloc ] initWithFrame:[scrollView bounds]];
htmlView.frame = CGRectMake(10,10,280,360);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[htmlView loadRequest:requestObj];
scrollView.contentSize = [htmlView bounds].size;
[scrollView addSubview:htmlView];
[detailsViewController.view addSubview:htmlView];
[htmlView release];
htmlView = nil;
[scrollView release];
scrollView = nil;
[[self navigationController] pushViewController:detailsViewController animated:YES];
[detailsViewController release];
}
All of the remote content that gets fed to the UIWebView comes from a web service that I wrote. The first screenshot is what is presented when a word is selected from the list view titled "Glossary"
This all is great until you follow a link, in this case clicking on the "frame" link in the UIWebView content. The new content gets loaded but I need to tell the nav bar that the UIWebView has changed so I can at least change the white title text to match the new content. What UIWebView methods should I implement and where should they go?
Set your view controller to be the UIWebView's delegate, then implement
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType