Obj C UIWebview go button click action - ios

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];
}

Related

if I clicked IBAction login button in login form,go to web view in ios

If I pressed login action button
- (IBAction)login button:(id)sender
I would like to go webview without using triggered segues.
Because I have two web views.If I pressed login button,I would like to go login webview, else I would like to go home webview. It depends on one button click.
I used delegate protocol and create two instance method and then,I would like to call method by using [self method name].delegate is okay but login button action didn't go to webview.
How can I do that?
piece of code in viewcontroller.m
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)loginCompleted{
NSString *fullURL = #"http://www.example.com/login";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[homeWebView loadRequest:requestObj];
}
-(void)homeCompleted{
NSString *fullURL = #"http://www.example.com/home";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[homeWebView loadRequest:requestObj];
}
- (IBAction)loginEvent:(id)sender {
if ([sender isEqual:loginbtn]) {
[self loginCompleted];
NSLog(#"Button pressed");
} else {
NSLog(#"Button pressed2"); }
}
Where is your loginbtn? How you set it?
set it's tag
loginbtn.tag = 1
In loginEvent compare the tag like this
if (sender.tag == 1) {
[self loginCompleted];
NSLog(#"Button pressed");
} else {
NSLog(#"Button pressed2");
}
You can select and deselect your button depending on what action you want to trigger: loginbtn.isSelected=true. And then:
- (IBAction)loginEvent:(id)sender {
if ([sender isSelected]) {
[self loginCompleted];
NSLog(#"Button pressed");
} else {
NSLog(#"Button pressed2");
}
}
(I write in Swift so it might be written a bit differently)
What you say 'If I pressed login button,I would like to go login web view,else I would like to go home web view.It depends on one button click.' causes me confused.What are the 'else cases' ?
I guest you are hoping to load the home page first,if the user press login button,it goes to the login page.
If it's true,you should add requestObj to the view controller's property,cancel the request if needed when the user press login button.
You say you have two webViews,but you load login request to the homeWebView see loginCompleted method

UIWebview not showing editview on first tap

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.

how to get UIPopoverController from UIWebView

I load a webpage in a uiwebviewcontroller,after click one link, it will pop a popovercontroller, is it possible to get this controller in my code?
Actually, this popovercontroller is not created by my code. The html detect the webpage is loaded by iDevice and pop this. That means, if I use safari to open webpage, it also will display this popovercontroller.
Thanks.
implement the UIWebView delegate method.
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
if([urlString isEqualToString :#"abc.com") // link on which want to open popoverview
{
UIPopoverController itemPopover = [[UIPopoverController alloc] initWithContentViewController:viewController];
[itemPopover presentPopoverFromRect:customCell.addImage.bounds inView:webViewpermittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
return NO; //if wanted to load the link on UIWebview return YES else return NO
}
return YES;
}

load UIWebView when clicking a button

-(IBAction)loadWebView
{
NSString * url = [NSString stringWithFormat:#"%#", [_urlArray objectAtIndex:_urlInt] ];
NSLog(#"_urlInt: %d",_urlInt);
NSLog(#"get url: %#",url);
//[self.webView loadRequest:[NSURLRequest requestWithURL:[ NSURL URLWithString: url ] ] ];
[self.webView loadRequest:[NSURLRequest requestWithURL:[ NSURL URLWithString:#"http://www.google.com"]]];
}
The above is my code in an iPad project.
It triggers this method when clicking a button on the same View Controller or click a row of a table on different View Controller.
Values of _urlArray and _urlInt are from the table when I click a row of the table. I can get the url in this method but I cannot relaod the UIWebView. However, when I modify the url to the home page of google and I click the button, the page can be reload to google.com.
I cannot get the reason. Could someone teach me that?
Thanks...

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