iPhone EXC_BAD_ACCESS cuando se usan bloques
Estoy tratando de crear una devolución de llamada simple usando bloques. Tengo un MainViewController que agregaSubView a otro DatePickerViewController.view. Creé un bloque como este
typedef void(^DateChangedBlock)(NSDate*);
Y tengo un método en mi DatePickerViewController llamado
setOnDateChangedCallback:(DateChangedBlock)callback
Almaceno la devolución de llamada en una propiedad de DatePickerViewController. La vista de DatePickerViewController es una instancia de UIDatePicker, he vinculado una IBAction al valor cambiado a un método que hace esto.
- (IBAction)dateChanged:(id)sender {
if (dateChangedCallback != nil)
{
dateChangedCallback(nil);
}
}
Así es como registro el bloque en MainViewController
DatePickerViewController *dateController = [[DatePickerViewController alloc] initWithNibName:@"DatePickerView" bundle:nil];
self.datePicker = dateController;
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)];
[self.view addSubview:textView];
DateChangedBlock myBlock = ^(NSDate *newDate) {
textView.text = @"testing";
};
[self.datePicker setOnDateChanged: myBlock];
[self.datePicker dateChanged:self]; // force trigger (this works).
Cuando fuerzo a activar el método dateChanged en el DatePickerViewController, no funciona ningún problema. Pero cuando el selector de fecha en sí activa el método a través de la IBAction, obtengo un error EXC_BAD_ACCESS. El error ocurre en este método en la línea "int retVal".
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); // THREAD 1: program received EXC_BAD_ACCCESS.**
[pool release];
return retVal;
}
¿Qué estoy haciendo mal