ok so I fixed it... (or more to the point used the app documentation code to do so) - for anyone else wanting to do these same code is below
Everything works except that now I am getting
Code:
warning:'UIViewController' may not respond to '-viewDidUnload'
in the -(void)viewDidUnload
I have read around and either the fixes posted don't apply or (and this is probably more likely) I just don't get it...
the app seems to work though...
h.
Code:
#import <UIKit/UIKit.h>
@interface Case33ans : UIViewController <UITextFieldDelegate, UIWebViewDelegate>
{
UIWebView *myWebView;
}
@property (nonatomic, retain) UIWebView *myWebView;
@end
m.
Code:
#import "Case33ans.h"
@implementation Case33ans
@synthesize myWebView;
- (void)dealloc
{
myWebView.delegate = nil;
[myWebView release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path;
NSBundle *thisBundle = [NSBundle mainBundle];
NSURL *instructionsURL;
self.title = NSLocalizedString(@" ", @"");
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
self.myWebView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease];
self.myWebView.backgroundColor = [UIColor whiteColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: self.myWebView];
path = [thisBundle pathForResource:@"Case33ans" ofType:@"html"];
instructionsURL = [[NSURL alloc] initFileURLWithPath:path];
[myWebView loadRequest:[NSURLRequest requestWithURL:instructionsURL]];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// release and set to nil
self.myWebView = nil;
}
#pragma mark -
#pragma mark UIViewController delegate methods
- (void)viewWillAppear:(BOOL)animated
{
self.myWebView.delegate = self; // setup the delegate as the web view is shown
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.myWebView stopLoading]; // in case the web view is still loading its content
self.myWebView.delegate = nil; // disconnect the delegate as the webview is hidden
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// we support rotation in this view controller
return YES;
}
// this helps dismiss the keyboard when the "Done" button is clicked
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]];
return YES;
}
#pragma mark -
#pragma mark UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// finished loading, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// load error, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// report the error inside the webview
NSString* errorString = [NSString stringWithFormat:
@"<html><center><font size=+5 color='red'>An error occurred:<br>%@</font></center></html>",
error.localizedDescription];
[self.myWebView loadHTMLString:errorString baseURL:nil];
}
@end
thanks, - frank.