Guest User

Untitled

a guest
Aug 24th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. ARC: Getting EXC_BAD_ACCESS from inside block used in delegate method
  2. - (void)loginViewDidSubmit:(MyLoginViewController *)loginController
  3. {
  4. NSString *user = loginController.usernameLabel.text;
  5. NSString *pass = loginController.passwordLabel.text;
  6.  
  7. __block MyLoginViewController *theController = loginController;
  8. [self loginUser:user withPassword:pass callback:^(NSString *errorMessage) {
  9. DLog(@"error: %@", errorMessage);
  10. DLog(@"View Controller: %@", theController); // omit this: all good
  11. theController = nil;
  12. }];
  13. }
  14.  
  15. [delegate loginViewDidSubmit:self];
  16.  
  17. (method shown above calls the loginUser: method, which does something like:)
  18. httpDelegate.currentCallback = callback;
  19. httpDelegate.currentConnection = // linebreak for readability
  20. [[NSURLConnection alloc] initWithRequest:req
  21. delegate:httpDelegate
  22. startImmediately:YES];
  23.  
  24. - (void)connection:(NSURLConnection *)aConnection
  25. didFailWithError:(NSError *)error
  26. {
  27. if (NULL != currentCallback) {
  28. currentCallback([error localizedDescription]);
  29. self.currentCallback = NULL;
  30. }
  31. }
  32.  
  33. - (void)loginUser:(NSString *)user withPassword:(NSString *)pass callback:(void (^callback)(NSString *))
  34. {
  35. callback = [callback copy];
  36.  
  37. httpDelegate.currentCallback = callback;
  38.  
  39. MyCallbackType aCallback = callback;
  40. httpDelegate.currentCallback = aCallback;
Add Comment
Please, Sign In to add comment