I'm developing an application that uses NSURLConnection a lot. I want content to be loaded dynamically, so I have to implement a lot of delegates for this to work.
In order to reduce the number of delegates, I created a class (AbstractURLConnection) that is < NSURLConnectionDelegate>.
I'm currently using a login view (and it's controller) to test the behavior of the NSURLConnectionDelegate class. Here are is my AbstractURLConnection class:
AbstractURLConnection
In LoginViewController I then do the following:
@interface LoginViewController : UIViewController {
AbstractNSUrlConnection *au;
}
@property (strong, nonatomic) AbstractNSUrlConnection <NSURLConnectionDelegate> *au;
- (void) handleResponse:(NSMutableData *) data;
and in the .m file:
- (IBAction)login:(id)sender {
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://myapp.dev:8887/users/login"]];
au = [[AbstractNSUrlConnection alloc] initWithRequest:req sender:self withSelector:@"handleResponse:" andRequestMethod:[AbstractNSUrlConnection MethodTypePOST]];
}
- (void) handleResponse:(NSMutableData *) data{
NSLog(@"called back");
}
When I run the application, my LoginView pops up and when I press the login button, the login function gets called. The connection is established and the callback method (handleResponse) is called too.
When I press the login button a second time, however, I get a EXC_BAD_ACCESS error to the handleResponse method.
I suppose that the sender is cleaned up when I press the button a second time, but I don't know how to solve this. Any idea what might cause this?
Thanks in advance,
Jordy