How to use the HTML Template In Xcode? - iphone

can some one tell me how i can use html template on the View Control?

if you want to use existing html page you have then you should use ---
NSString *path = [[NSBundle mainBundle] pathForResource:#"MyWebPage" ofType:#"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
OR
If you want to use your own code for html then you can use
[myWebView loadHTMLString:#"<html><head></head><body style=\"font-family: sans-serif;\"> .... </body></html>" baseURL:nil];
Hope you were helped....

Related

Passing NSString to Webview

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

UIWebView and Safari content not looking the same

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

UIWebView: how do I start from a blank view each time?

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

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

iPhone SDK: WebView how to specify a local URL?

I have HTML files that I want to load locally. I have included the files in the resources folder in XCode. I am not sure what the syntax is to load them.
This is the code I use to connect to say google.
NSString *urlAddress=#"http\\someurl";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webHelpView loadRequest:requestObj];
Could someone provide an example where a HTML file is loaded locally.
Thanks in advance.
This is the only code that worked for me.
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"SettingsHelp.html"];
NSURL *url = [NSURL fileURLWithPath:path isDirectory:NO];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
Thanks all for the help.
Can't you just do
NSURL *url = [NSURL URLWithString:#"file:///path/to/file"];
?
Sure, here is some code from an app that loads a locallly stored html page into a web view:
- (void) viewDidLoad
{
// Load the content into the view
NSString* path = [NSString stringWithFormat: #"%#/index.html",
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]];
[webView_ loadRequest: [NSURLRequest requestWithURL: [NSURL fileURLWithPath: path]]];
}