2011-10-09 40 views
1

我是否錯誤地聲明或使用了「course」變量?我需要將用戶選擇的課程對象發送給子UIViewController,並且沒有任何運氣。此代碼工作2次,然後第三次失敗。如何調試:*** - [<func_name> controllerWillChangeContent:]:發送到釋放實例的消息0x5909c60

運行時的錯誤,我得到的是:

2011-10-09 17:04:41.403 [] *** -[vcListGrades controllerWillChangeContent:]: message sent to deallocated instance 0x5909c60 

當我發現使用調試器命令的地址:「信息的malloc歷史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歷史堆棧

(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; 

這裏是我的NSFetchedResultsController

@synthesize fetchedResultsController = _fetchedResultsController; 
+0

獲取的結果控制器是如何創建的? –

+0

什麼是課程?你不需要做'[listGradesViewController setCourse:[course retain]];' –

+0

@ott - 我試過上面的路線,但沒有喜悅。注意更新 - 違規行實際上是它下面的行,我分配新的viewcontroller。 – phil

回答

0

請顯示異常堆棧.m文件。當然,你意識到,當你分配「課程」時,這並沒有得到保留。保留你需要分配給「self.course」。

+0

確定 - 添加它。會嘗試自我。以及。 – phil

+0

我曾經表示,違規行(428)是「課程」分配線。違規行實際上是它下面的行。這裏是:vcListGrades * listGradesViewController = [[vcListGrades alloc] initWithNibName:@「vcListGrades」bundle:nil]; // <<這是由錯誤標記的行。 – phil

+0

我沒有問過malloc-history標記過哪條線,我詢問了異常堆棧。 –

相關問題