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.
Related
I am new in iPhone development and I want to perform a simple task with UIWebView. I just want to display an URL on a new view when i click on a button present in the root view controller. But when i do this i get an exception
NSInvalidArgumentException', reason: 'Application tried to present a
nil modal view controller on target .
Here is my code.
WebViewController.m (This is the view where i have kept the UIWebView)
NSURL *url = [[NSURL alloc] initWithString:#"www.google.com"];
NSURLRequest *requestobj = [NSURLRequest requestWithURL:url];
[webview.delegate self];
[self.view addSubview:webview];
[webview loadRequest:requestobj];
Hope that you have defined the webview by the following. UIWebview is a subclass of UIView.
IBOutlet UIWebView *webView;
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];
Issue
Well the error says you are trying to push a nil value.
Things to check
Make sure the WebViewcontroller is initialised properly[it cannot be nil]
Make sure the nib name is WebViewController
Files owner has class name WebViewController
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.
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.
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.
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.