I am trying to get a URL from my user in a TextField and then process the result. Presently an exception is being thrown with the following -[UITextField length]: unrecognized selector sent to instance
in the NSURLRequest below when I supply URLWithString: (NSString *)self.urlNameInput]
.
myViewController.h
@class myViewController;
@interface myViewController : UIViewController <UITextFieldDelegate, NSURLConnectionDataDelegate, NSURLConnectionDelegate>
{
NSMutableData *receivedData;
}
@property (weak, nonatomic) IBOutlet UITextField *urlNameInput;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end
myViewController.m
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.urlNameInput) {
[textField resignFirstResponder];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString: (NSString *)self.urlNameInput] cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [NSMutableData data] ;
} else {
// Inform the user that the connection failed.
NSLog(@"Their is an error with that URL.");
}
}
return YES;
}