views:

17

answers:

1

Hi guys,

I have created a web view programmatically. This works perfect. The code is below. What I need to try and do now is inject NSStrings into it. I have an array of 30 strings. 15 Headings and 15 body-texts.

Is it possible to get these displayed inside the webview? I'm guessing I need to change them into a HTML, imaybe reformat them all into 1 long NSString with html-tags and linebreaks and newling-tags maybe?

Anybody able to help me with some pointers/code snippets to get me on the right track and moving the the correct direction please?

- (void) initUIWebView
{
aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 290)];//init and 
create the UIWebView

aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | 
UIViewAutoresizingFlexibleWidth);

[aWebView setDelegate:self];

NSString *urlAddress = @"http://www.google.com"; // test view is working with url to 
webpage

NSURL *url = [NSURL URLWithString:urlAddress];


NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[aWebView loadRequest:requestObj];

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
[[self view] addSubview:aWebView];  

} 

Thanks -Code

A: 

Instead of using the loadRequest method you will have to use the loadHTMLString method of UIWebView The following code might help you in displaying the NSString in UIWebView

NSString *html = @"<html><head></head><body>The Meaning of Life<p>...really is <b>42</b>!</p></body></html>";  
[webView loadHTMLString:html baseURL:nil];

Hope this will resolve your issue...

Atulkumar V. Jain
Thank you Atulkumar :)
Code