Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ARC: Getting EXC_BAD_ACCESS from inside block used in delegate method
- - (void)loginViewDidSubmit:(MyLoginViewController *)loginController
- {
- NSString *user = loginController.usernameLabel.text;
- NSString *pass = loginController.passwordLabel.text;
- __block MyLoginViewController *theController = loginController;
- [self loginUser:user withPassword:pass callback:^(NSString *errorMessage) {
- DLog(@"error: %@", errorMessage);
- DLog(@"View Controller: %@", theController); // omit this: all good
- theController = nil;
- }];
- }
- [delegate loginViewDidSubmit:self];
- (method shown above calls the loginUser: method, which does something like:)
- httpDelegate.currentCallback = callback;
- httpDelegate.currentConnection = // linebreak for readability
- [[NSURLConnection alloc] initWithRequest:req
- delegate:httpDelegate
- startImmediately:YES];
- - (void)connection:(NSURLConnection *)aConnection
- didFailWithError:(NSError *)error
- {
- if (NULL != currentCallback) {
- currentCallback([error localizedDescription]);
- self.currentCallback = NULL;
- }
- }
- - (void)loginUser:(NSString *)user withPassword:(NSString *)pass callback:(void (^callback)(NSString *))
- {
- callback = [callback copy];
- httpDelegate.currentCallback = callback;
- MyCallbackType aCallback = callback;
- httpDelegate.currentCallback = aCallback;
Add Comment
Please, Sign In to add comment