Я объявил или использовал переменную "курс" неправильно? Мне нужно отправить выбранный пользователем объект курса дочернему UIViewController, и мне не везет. Этот код работает 2 раза, а затем завершается с ошибкой в третий раз.
Ошибка времени выполнения, которую я получаю:
2011-10-09 17:04:41.403 [] *** -[vcListGrades controllerWillChangeContent:]: message sent to deallocated instance 0x5909c60
Когда я нахожу этот адрес с помощью команды отладчика: «info malloc-history 0x5909c60», он указывает на код, представленный ниже.
// Вот код обидчика
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:YES];
course = [_fetchedResultsController objectAtIndexPath:indexPath];
//create the new controller for next drill level into table
vcListGrades *listGradesViewController = [[vcListGrades alloc] initWithNibName:@"vcListGrades" bundle:nil];
// ^^^ эта строка выше помечена ошибкой.
// take the MO context with you to the next level of table drilling
listGradesViewController.managedObjectContext = self.managedObjectContext;
// take the school_courseName record that was just clicked with you as you drill into next table
[listGradesViewController setCourse: course];
// deselect the row that was just clicked - this according to mac style guide
[tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:YES];
//push new controller onto stack and go for it
[self.navigationController pushViewController:listGradesViewController animated:YES];
[listGradesViewController release];
}
// Вот как определяется курс в .h файле
@interface vcListCourses : UITableViewController <NSFetchedResultsControllerDelegate> {
NSFetchedResultsController *_fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
Schoolyear *_schoolyear;
Course *course;
}
...elipse
@property (nonatomic, retain) Course *course;
// Синтезировать строку в файл .m
@synthesize course;
и вот стек информации malloc-history
(gdb) info malloc-history 0x5909c60
Alloc: Block address: 0x05909c60 length: 176
Stack - pthread: 0xacff42c0 number of frames: 19
0: 0x991e990b in malloc_zone_calloc
1: 0x991ea837 in calloc
2: 0x11322d4 in class_createInstance
3: 0xefe5d8 in +[NSObject(NSObject) allocWithZone:]
4: 0xefe3da in +[NSObject(NSObject) alloc]
5: 0x83b6 in -[vcListCourses tableView:didSelectRowAtIndexPath:] at vcListCourses.m:428
6: 0x36ab68 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
7: 0x360b05 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
8: 0x7279e in __NSFireDelayedPerform
9: 0xfbb8c3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
10: 0xfbce74 in __CFRunLoopDoTimer
11: 0xf192c9 in __CFRunLoopRun
12: 0xf18840 in CFRunLoopRunSpecific
13: 0xf18761 in CFRunLoopRunInMode
14: 0x19311c4 in GSEventRunModal
15: 0x1931289 in GSEventRun
16: 0x301c93 in UIApplicationMain
17: 0x26e9 in main at main.m:14
18: 0x2665 in start
Это выглядит правильно?
Я определяю свой nsfetchedResultsController следующим образом в файле rootviewcontroller.h
The @interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
NSFetchedResultsController *_fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
UIBarButtonItem *addButton;
Schoolyear *year;
}
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
Вот файл .m для моего NSFetchedResultsController
@synthesize fetchedResultsController = _fetchedResultsController;