I am very new to obj-c (about 1 day) and i have read the documentation on how to call methods and how to modify strings and i have used similar code in another program and it worked fine. I m programming a simple web browser for the iphone to teach myself about WebViewController library. When i compile this it gives me the warning " WebViewController may not respond to -parseURl:" at line 17 in the .m file and when i run it i throws the error "NSInvalidArgumentException" in the console.
《网页浏览器守则》:
#import <UIKit/UIKit.h>
@interface WebViewController : UIViewController {
IBOutlet UIWebView *webView;
IBOutlet UITextField *textField;
}
NSString *urlAddress;
NSURL *url;
NSURLRequest *requestObj;
- (IBAction)gotoAddress:(id)sender;
- (NSString*) parseURL:(NSString*)str;
@property (nonatomic, retain) UIWebView *webView;
@end
网页记录
#import "WebViewController.h"
@implementation WebViewController
@synthesize webView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Initialization code
}
return self;
}
- (IBAction)gotoAddress:(id)sender {
urlAddress = textField.text;
urlAddress = [self parseURl:urlAddress];
url = [NSURL URLWithString:urlAddress];
requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
NSLog(@"urlAddress= %s", [urlAddress cStringUsingEncoding:1]);
}
- (NSString*) parseURL:(NSString*)str {
NSLog(@"made it");
NSString *httpPart = @"http://";
if ([str rangeOfString:httpPart].location == NSNotFound) {
NSString *correctURL = [NSString stringWithFormat:@"%@%@", httpPart, str];
return correctURL;
}
else {
return str;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn t have a superview
// Release anything that s not essential, such as cached data
}
- (void)dealloc {
[webView release];
[super dealloc];
}
@end
Thanks for the help