我是否错误地声明或使用了“课程”变量?我需要将用户选择的课程对象发送到子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;
这是info malloc-history stack
(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
这看起来不错吗?
我在rootviewcontroller.h文件中定义了这样的nsfetchedResultsController
The @interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
NSFetchedResultsController *_fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
UIBarButtonItem *addButton;
Schoolyear *year;
}
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
这是我的NSFetchedResultsController的.m文件
@synthesize fetchedResultsController = _fetchedResultsController;
答案 0 :(得分:0)
请显示异常堆栈。当然,你意识到,当你指定“课程”时,那就不会被保留。保留你需要分配给“self.course”。