two webPage on single UIWebView - iphone

i am making an iPad application,
i want to load 2 webPage on single UIWebView one after another,
1st webpage should come when i load my application,and 2nd webpage should come on click of cell of tableView,
so,inside my didLoad method i am writing this (1st webpage),
NSString *urlAddress = #”http://www.google.com”;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
it works fine..
but on the same page on same webview on click of cell of tableView i want to load another page,(2nd webpage)
i written code for the same, when i click on cell of tableView graph is not displaying,
do i need to clear webpage or reload webpage something like that ?
Help Me Guys, Thanx in Advance !!

call this method,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *urlAddress = #”http://www.google.com”;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}

I see from your comment that you use a wrong URL format for the second request:
NSString *urlAddress1 = #”yahoo.com”; //Create a URL object.
NSURL *url1 = [NSURL URLWithString:urlAddress1]; //URL Requst Object
NSURLRequest *requestObj1 = [NSURLRequest requestWithURL:url1]; //Load the request in the
UIWebView. [webView loadRequest:requestObj1];
The URL has to begin with
http://
Otherwise it won't work.

Related

Navigating back from UIViewController causes crash

I am just using this piece of code in viewDidLoad method. It only opens the web page in UIWebView and that's it. But when I go back to the previous view It cause crash.
here is the code:
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[moreWeb loadRequest:requestObj];
Just stop loading like this:
-(void)viewWillDisappear:(BOOL)animated{
[moreWeb stopLoading];
moreWeb.delegate = nil;
}
it'll work fine.

UIWebView cannot redirect

I'm new to Objective-C.
I have made an application which redirects a string to a webView. I want that webView should load wikipedia and should search the contents present in that string.
I have written like this...
NSString *urlString=[NSString stringWithFormat:#"http://en.wikipedia.org/wiki/Main_Page/search=%#",str1];
//[urlString stringBy];
NSLog(#"url %#",urlString);
NSURL *url=[NSURL URLWithString:urlString];
NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];
[webView loadRequest:request];
NSString *urlAddress = #”http://www.google.com”;
// Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
// URL Request Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
// Load the request in the UIWebView.
[webView loadRequest:requestObj];
Good luck

Going to a UIWebView from an IBAction

I would like to know how do I load a web view from an "- (IBAction) buttonPressed" function.
IBOutlet UIWebView *webView;
-(IBAction)click
{
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
Make the -(IBAction) load a new view, and put a UIWebView in that new view.

release contents of UIWebView

I have a ViewController and UIWebView created in Interface Builder in it. I fill webView with data like this:
NSString *urlAddress = self.artUrl;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[self.webView loadRequest:requestObj];
How should I release content of this webView in didReceiveMemoryWarning?
Thanks
You either release the whole web view (if it is off-screen for example), or nothing at all. If you really need to release the contents, load a blank page.

How to load a LOCAL .html file with a UIWebview?

I am trying to load an HTML file stored locally on the apps documents directory using the method shown below. It ain't workin. What am I doing wrong?
NSLog(#"Loading Saved Copy!");
urlAddress = [[self documentsDirectory] stringByAppendingPathComponent:#"/Profile/profile.html"];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
Use +[NSURL fileURLWithPath:isDirectory:] instead.