【发布时间】:2011-04-21 16:56:50
【问题描述】:
我对 Objective-C 和 Cocoa 还是很陌生,但我正在努力学习。我正在创建一个简单的 ToDo 管理器,但我不断收到 EXC_BAD_ACCESS 崩溃,我不知道为什么。崩溃发生在我的 main.m 文件中“return NSApplicationMain(argc, (const char **)argv);”所以真的很难调试。
这是我的应用委托的实际实现文件。
#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 的回溯。
-
将回溯添加到主帖。
标签: objective-c cocoa