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
Related
I have UIWebView i want to load link in it but it does not show any thing here is the code which i am using it does not show
fileName has value http://www.google.com
NSURL *url = [NSURL fileURLWithPath:fileName];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
try like this,replace fileURLWithPath with URLWithString
NSString *fileName= #"http://www.google.com";
NSURL *url = [NSURL URLWithString:fileName];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview setScalesPageToFit:YES];
[webview loadRequest:request];
**fileURLWithPath** is used when there is a path containing your URL.
But in your case there is a direct URL so you should use like following
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#",#"http://www.google.com"]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
//Create a URL String.
NSString *urlString = [NSString stringWithFormat:#"http://www.google.com"];
//Create a Legeal URL object.
NSURL *MyUrl = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:MyUrl];
// set Fit page to WebView
[webView setScalesPageToFit:YES];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
NOTE : Don't forget to Add webView to self.View OR if you add with XIB then make sure you connection is proper;
Try this ..... !!!
UIWebView * aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
NSString *fileName= #"http://click-labs.com";
NSURL *url = [NSURL URLWithString:fileName];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[aWebView setScalesPageToFit:YES];
[aWebView loadRequest:request];
[ self.view addSubview:aWebView];
I have an NSString called status and I am trying to pass that variable to load a webView. The app is crashing here, but I don't know what I am doing wrong? Does anyone see anything wrong with the request?
[webView loadRequest:[NSURLRequest requestWithURL:[NSString
stringWithFormat:#"http://www.website.com/page.php?status=%#", status]]];
requestWithURL accepts NSURL, So you need to convert string into NSURL
Try this,
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.website.com/page.php?status=%#", status]]]];
+[NSURLRequest requestWithURL:] is expecting you to give it an NSURL object. You're giving it an NSString. Don't do that. :)
NSString *urlAddress = [NSString stringWithFormat:#"http://www.website.com/page.php?status=%#", status];
//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 this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.website.com/page.php?status=%#", status]]]];
I have a UIWebView which is adapted to a mobile style of a forum I have. In Safari, it looks and works great.
However, inside my WebView there is a disastrous problem.
When quoting or editing a post, HTML is displayed inside of BBcode. Furthermore, posting code results in ignored line breaks.
The webview is loaded like this:
//display the webview
NSString *fullURL = #"http://www.mysite.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
[_webTest loadRequest:requestObj];
Change your this line:
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
With this line & check:
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
Do you want to load a html-string in your webView?
If it is the thing than following may help you:
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:bundlePath];
NSString *htmlString = [bundlePath pathForResource:#"index" ofType:#"html"] ;
[webView loadHTMLString:htmlString baseURL:baseURL];
I'm looking up web pages using UIWebView and NSURLRequest and it's working fine, but I want it to start with a blank page each time, rather than displaying the results of the last URL lookup. Is there an easy way to do that?
I'm doing this in viewDidLoad:
wikiText = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 370)] autorelease];
[wikiView addSubview:wikiText];
...and then I load the UIWebView like this:
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
Start with this first.
[wikiText loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#""]]];
This loads a blank page first. then open your usual URL.
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
We can also use Html tags like this
[wikiText loadHTMLString:#"<html><head></head><body></body></html>" baseURL:nil];
Then after you can load your actual url
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
There is no need to load load blank URL, you just use viewWillAppear, according to this, every time when your view will appear then webView will load your page and initially gives you white blank page then your url page.
-(void)viewWillAppear:(BOOL)animated
{
wikiText = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 370)] autorelease];
[wikiView addSubview:wikiText];
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
}
How to use uiwebview to show some web page for url request? i dont know how to do it. who can tell me how to do it? has any opensource? thanks.
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];