I'm wondering whether there's a control to display html embedded data in iphone. I need to display the information as it is on the web. The data is saved into it database together with its html tag.
So is there anyway for me to display the data accordingly..
You can use a UIWebView and load HTML using
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
you can use a UIWebView and loadHTMLString method to load the data in HTML.
You can also change html page contents at run time using the javascript.
You can use webview for displaying displaying html embbed data.
Example is given here :
To load remote html file:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.apple.com"]]];
To load local html file:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
To load html string:
[webView loadHTMLString:#"<img src=test.png>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
Related
I made an hybrid app between objective C and javascript. My app works so:
When I press on the first button it will load a UIWebView
In this UIWebView I can save the html to the Documents folder
When I save the website I create a JSON to store informations and I save this JSON to Documents folder
When I press the second button, it will load another UIWebView in which there are a mobile site that read informations from JSON and present this data in a html list
When I press on the name of one site it will load the site from Documents folder
The first 4 points works great, but when I press on the site title I've trouble, indeed, the UIWebView shows me a page in which there are written that the page it's not stored on this server. When I navigate with Finder to the Documents folder of my app and I double click on the html site it shows me it in Safari. Why when I load it with an UIWebView doesn't work? I will post here a screenshot to understand my flow.
CODE: I post here the code to load the html:
viewDidLoad method where I call the method to load my page
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.webView.delegate = self;
//[self loadWebsite:#"http://localhost/root/main/index.html"];
[self loadWebsite:#"http://192.168.2.1/root/main/index.html"];
}
loadWebsite method
-(void)loadWebsite:(NSString*)site
{
NSURL *url = [NSURL URLWithString:site];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView setScalesPageToFit:YES];
[self.webView loadRequest:request];
}
This seems like a problem with how you are loading your html file into the webview. You should post the code where you are loading the uiwebview.
To load a webview with a local file use the following code :
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"htmlfilename" ofType:#"html" inDirectory:#"Documents"]];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
You can refer to this post : Load resources from relative path using local html in uiwebview
I am using UIWebView to load HTML Page. From that HTML I have generated PDF file. My PDF file content changes as per the HTML data changes. when I change the Signature(Image) of the user in application respective PDF will not change to new signature. It shows the previous signature.
How can I reload that UIWebView?
[webView reload] should do the trick.
If you are using a new URL you can use [webView loadRequest:[NSURLRequest requestWithURL:theURL]];
If you are using same url with updated content use this.
UIWebView* webV=[[UIWebView alloc]init];
NSString* htmlString= #"Loading...";
[webV loadHTMLString:htmlString baseURL:nil];
[webV loadRequest:[NSURLRequest requestWithURL:mainURL]];
I want to open web page on the webView by passing the web url of that page. How is this possible?
You can load a website using this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://i.wrightscs.com"]]];
You can also load HTML into a UIWebView using this:
[webView loadHTMLString:#"<strong>It Work's!</strong>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
i am having problem with how to get the uiwebview loaded with local html file .provide the cod e as well i am having the hmtl file as fp_dis-1.html.
thanks in advance
Try this,
UIWebView *page;
[page loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"your-local-file-url" ofType:#"html"]isDirectory:NO]]];
I have a local HTML page which doesn't has any external link(css or images..)
I use method below to load it to a WebView
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;
it takes around 5-8 seconds to load this page, that's too slow. right?
but when I load that page in iPhone safari, it takes around 2 second.
I don't know why it is slow like that in my WebView.
I also did a Google search, but I couldn't find any answer.
To load local html file you should try this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
If you have the HTML as text then use the loadHTML:
[webView loadHTMLString:#"<html><body>Some HTML</body></html>" baseURL:nil];
It loads about 2 seconds for me (simple HTML).
Maybe you have some very large HTML and you read it from file?