我還是真正的新的Objective-C和Cocoa,但我努力學習。我正在創建一個簡單的ToDo管理器,但我不斷收到EXC_BAD_ACCESS崩潰,我不知道爲什麼。崩潰發生在我的main.m文件中「return NSApplicationMain(argc,(const char **)argv);」所以它很難調試。的Objective-C&EXC_BAD_ACCESS
這裏是我的應用程序委託我的實際執行文件。
#import "ToDoAppDelegate.h"
#import "Task.h"
@implementation ToDoAppDelegate
@synthesize textTaskName;
@synthesize taskDate;
@synthesize window;
@synthesize newTaskWindow;
@synthesize tableView;
@synthesize arrayController;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
taskArray = [[NSMutableArray alloc] init];
[taskArray retain];
}
- (IBAction)addTaskClick:(id)sender
{
[NSApp beginSheet:newTaskWindow modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:NULL];
[taskDate setDateValue:[NSDate date]];
}
- (IBAction)btnSaveClick:(id)sender
{
Task *newTask = [[Task alloc] init];
[newTask setTaskName:[textTaskName stringValue]];
[newTask setTaskDueDate:[taskDate dateValue]];
[arrayController addObject:newTask];
[newTask release];
[textTaskName setStringValue:@""];
[NSApp endSheet:newTaskWindow];
[newTaskWindow orderOut:self];
}
- (IBAction)btnCancelClick:(id)sender
{
[NSApp endSheet:newTaskWindow];
[newTaskWindow orderOut:self];
}
@end
會發生什麼事是當btnSaveClick方法被調用時,我得到的方法執行完畢後馬上EXC_BAD_ACCESS崩潰。
這裏是崩潰的回溯:
(gdb) bt
#0 0x00007fff851d212d in objc_msgSend()
#1 0x00007fff80f9d1e6 in _CFAutoreleasePoolPop()
#2 0x00007fff809a0fe0 in -[NSAutoreleasePool drain]()
#3 0x00007fff8780451f in -[NSApplication run]()
#4 0x00007fff877fd1a8 in NSApplicationMain()
#5 0x0000000100001a82 in main (argc=1, argv=0x7fff5fbff638) at /Users/mattwise1985/Documents/Development/xCode Projects/ToDo/ToDo/main.m:13
由於這只是一個測試項目,如果有人想下載它檢查出我有什麼錯了,我不介意。它可以從這裏下載:http://www.narfsoft.com/downloads/ToDo.zip
顯示我們從GDB回溯當你崩潰。 – 2011-04-21 17:00:16
將回溯添加到主帖子。 – QuantumPhysGuy 2011-04-21 17:10:16