调试方法:***-[< func_name> controllerWillChangeContent:]:发送到已释放实例0x5909c60的消息 [英] How to debug: *** -[<func_name> controllerWillChangeContent:]: message sent to deallocated instance 0x5909c60
问题描述
我是否错误地声明或使用了"course"变量?我需要将用户选择的课程对象发送到子UIViewController,并且没有任何运气.该代码工作两次,然后第三次失败.
Have I declared or used the "course" variable wrongly? I need to send the user-selected course object over to the child UIViewController and am not having any luck. This code works 2 times and then fails the third time through.
我得到的运行时错误是:
The runtime error I get is:
2011-10-09 17:04:41.403 [] *** -[vcListGrades controllerWillChangeContent:]: message sent to deallocated instance 0x5909c60
当我使用调试器命令"info malloc-history 0x5909c60"找到该地址时,它指向下面显示的代码.
When I find that address using the debugger command: "info malloc-history 0x5909c60", it points me to the code that is presented below.
//这是有问题的代码
- (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];
//^^^上面的这一行是错误所标记的行.
// ^^^ this line above is the line flagged by the error.
// 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文件中的路线定义方式
//Here's how course is defined in the .h file
@interface vcListCourses : UITableViewController <NSFetchedResultsControllerDelegate> {
NSFetchedResultsController *_fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
Schoolyear *_schoolyear;
Course *course;
}
...elipse
@property (nonatomic, retain) Course *course;
//.m文件中的合成行
//Synthesize line in .m file
@synthesize course;
这是信息malloc-history堆栈
and here is the 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
I define my nsfetchedResultsController like this in the rootviewcontroller.h file
The @interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
NSFetchedResultsController *_fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
UIBarButtonItem *addButton;
Schoolyear *year;
}
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
这是我的NSFetchedResultsController的.m文件
Here is the .m file for my NSFetchedResultsController
@synthesize fetchedResultsController = _fetchedResultsController;
推荐答案
请显示异常堆栈.当然,您意识到,当您分配课程"时,并不会保留该课程.要保留,您需要分配给"self.course".
Please display the exception stack. And you realize, of course, that when you assign "course", that's not getting retained. To retain you need to assign to "self.course".
这篇关于调试方法:***-[< func_name> controllerWillChangeContent:]:发送到已释放实例0x5909c60的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!