Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pcunix

macrumors newbie
Original poster
Aug 1, 2009
12
7
I am brand new to all this and am barely at the drag a button and connect it to the delegate stage.

I need to read HTML pages and display them. I've pawed through and Googled and there seem to be half a dozen or more ways to approach this - I'm wondering which would make the most sense.

I'm not implementing a browser. This is just snippets of HTML, say something like

Code:
<h2>Hey there!</h2>
<p>Welcome to blah-blah.  Click the "Continue" button below to get started.</p>

The button would a normal Interface Builder piece. Click it and it's going to read and display something else from the file. Just a big loop, picking this or that, display, more buttons, on we go. Seems simple enough.

So, I found the stuff for opening and reading files. I've read my file and have that chunk of HTML in a string or an array and now it's time to write it to.. to what? What's the best choice here?

(and if you feel up to it, a little explanation of why sure wouldn't upset me)

Or.. would it be better to read the content over the Net? I'm thinking maybe 300K of content here total.. my impulse would be to bundle the file with the app but maybe I'm wrong??
 
The only realistic way to render HTML is to use UIWebView.

Well, I looked at that and it seems to want a URL also. I don't have a URL - I only have HTML in a string.

So

Code:
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

What's my baseURL??
 
Depends. When I use this in the SELOCTechWiki app in my signature I use a file URL to set the base to within the application bundle to allow me to load resources (CSS and images) from within the Resources folder.

If your files are 100% self contained then pretty much anything will do. You can probably pass nil in that case.
 
Depends. When I use this in the SELOCTechWiki app in my signature I use a file URL to set the base to within the application bundle to allow me to load resources (CSS and images) from within the Resources folder.

If your files are 100% self contained then pretty much anything will do. You can probably pass nil in that case.

Oh, ok - it's just relative links vs full path. Thanks.

But i'm still not getting something - I have to be missing something basic.

In my delegate.h I have:

Code:
#import <UIKit/UIKit.h>
#import <UIKit/UIWebView.h>

@interface q2AppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	UILabel *display;
	UIWebView *setv;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UILabel *display;
@property (nonatomic, retain) IBOutlet UIWebView *setv;

- (IBAction) click1: (id) sender;


@end

and in the .m I have

Code:
#import "q2AppDelegate.h"

@implementation q2AppDelegate

@synthesize window, display,setv;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch
	
    [window makeKeyAndVisible];
	
	return YES;
}

- (IBAction) click1: (id) sender
{


   NSString *html = @"<html><head><title>foo test</title></head><body><h2>Hello</h2><p>stuff</p></body></html>";  
	[setv  loadHTMLString:html baseURL:[NSURL URLWithString:@"/"]]; 
	
}
	
	- (void)dealloc {
    [window release];
    [super dealloc];
}


@end

Interface Builder Connections Inspector for the UIView shows that I have that connected to setv, and Build/Run says "Success" but nothing shows up on the click.
 
Can you check if setv is nil before setting the string? Are you 100% sure the webview is visible etc?

It works this morning. Could this be as simple as my forgetting to click Save in Interface Builder??? That seems to be all that I did when I hit this today.

Duh :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.