Loading url's in UIWebView - iphone

I have a UIViewController with a webView in it.
When tapping on a link, I would like to push a new controller and open the url in a new webview.
Is that possible?
Thanks in advance for your help.

You need to implement webView:shouldStartLoadWithRequest:navigationType: (docs here), push your new controller and return NO.
I imagine that you've already got a handle on loading a URL into a WebView so I leave it at that.

Related

UIWebView to View Controller?

I was wondering if anyone knew if this was possible?
I have a uiwebview as the first view controller which is showing a basic html page I made with the Facebook login screen. Can you login (in the uiwebview) and once it authorises you (in the uiwebview) it closes and launches the second view controller?
Does anyone know of a good example or tutorial for this?
If not can someone point me in the direction of a good FacebookSDK example or tutorial in Storyboard not XIB?
Thanks!
You should be using the FBLoginView and FBSession classes of the Facebook SDK to log in. You can just use the delegate callbacks from those to drive your next view controller.
I can't think of a reason you would want to bring up the facebook login page in a UIWebView , rather than doing the above. If for some reason you actually need to use a UIWebView , the webViewDidFinishLoad: method of UIWebViewDelegate might provide you with the hook you need.
Download the Facebook sdk from github and check the SessionLoginSample in samples. I think it has everything you need

A Label in View with UIWebView

I have a View, i would like to put a test ( a UILabel) witch when clicking it, it open me a web View with an URL ( WWW.mySite.com).
How i can do this please ?
thanks for your answers
Use a button, put the text into the button, hook up the actions from the button pressedUpInside to a function which will call the UIWebView's - (void)loadRequest:(NSURLRequest *)request with your URL.
Look up Apple documentation on UIWebView and use a UIButton connected to an IBAction. Always turn to the documentation when these kinds of questions come up. It is really through and usually pretty well done.

Updating address bar with current url from UIWebview

Like iPhone safari browser, I want to update UItextview with current url of UIWebView
I tried shouldStartLoadWithRequest delegate method, but I end up with url of some ads/iframe
If I use webViewDidFinishLoad delegate method, then address bar gets updated at the end of the request.
Please help me on the best approach.
You want to use the mainDocumentURL method on the NSURLRequest in webView:shouldStartLoadWithRequest:. This should contain the main document URL regardless of whether the page is loading or a resource on the page (e.g. a frame) is loading.
Use webviewDidFinishLoad when delegated from your webview, and then query it for the title with [webview stringByEvaluatingJavaScriptFromString:#"document.title"] or weboutWebView.request.URL.absoluteString for the url.

URL Loading Problem

I parsing the "http://feeds.epicurious.com/newrecipes" URL and i read the URLs as following format.
http://feeds.epicurious.com/~r/newrecipes/~3/TGBDO1Ld400/361889
When i put this above Url in UIWebview, it does not work.
But When i put this URL in web browser it will change automatically as the following format.
http://www.epicurious.com/recipes/food/views/Cherry-Cranberry-Sauce-361889?mbid=rss_epinr&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+newrecipes+%28Epicurious+-+New+Recipes%29
How to solve this issue. If anybody having any idea please answer me.
Thanks..
I was able to get that same link to load with a stock iPad split view controller that only contained an outlet to a UIWebView named "viewer". I called this code from viewDidLoad: in the root view controller:
[detailViewController.viewer loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://feeds.epicurious.com/~r/newrecipes/~3/TGBDO1Ld400/361889"]]];
Hope that helps.

custom Copy Responder in iphone

I have a webview in my application. I want to handle when user copies something from web view, my custom method - should be triggered. I have tried following.
I have placed following method in myViewCtr.m file
-(void)copy:(id)sender{
NSLog(#"hi ! Hello ");
}
But nothing working - what should I do to implement the same ?
You need to implement -copy: on the responder, not on the controller. So you need to subclass UIWebView and override -copy:.
Ahh ! I got something here from this question.
Direct sample from Apple itself.
Theory :)