This is basically the "hello world" of NSOutlineView
with a data source. All I do is drag an NSOutlineView
into the MainMenu.xib
window, connect it to an outlet, and then try to set it's datasource to a simple implementation. When I run it, I get Thread 1: EXC_BAD_ACCESS
, but the stack trace in the debugger is helping me.
(lldb) bt
* thread #1: tid = 0x158e35, 0x00007fff8948d097 libobjc.A.dylib`objc_msgSend + 23, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x00007fff8948d097 libobjc.A.dylib`objc_msgSend + 23
frame #1: 0x00007fff8839e590 AppKit`loadItemEntryLazyInfoIfNecessary + 120
frame #2: 0x00007fff883d3e5f AppKit`-[NSOutlineView _rowEntryForRow:requiredRowEntryLoadMask:] + 77
frame #3: 0x00007fff883d37d1 AppKit`-[NSOutlineView frameOfCellAtColumn:row:] + 323
frame #4: 0x00007fff885d5548 AppKit`-[NSTableView drawRow:clipRect:] + 1154
frame #5: 0x00007fff885d4f7d AppKit`-[NSTableView drawRowIndexes:clipRect:] + 776
...
When I set break points, I only see one of my methods getting called. (outlineView:numberOfChildrenOfItem:
) Here's my code. Any ideas?
It creates three simple "root" items, and returns a string for the values. That never get's called anyway, according to breakpoints.
In app delegate:
@implementation TmTrkAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
_outlineView.dataSource = [[TmTrkOutlineViewDataSource alloc] init];
}
@end
Data source:
@interface TmTrkOutlineViewDataSource : NSObject <NSOutlineViewDataSource>
@end
...
@interface TmTrkTagItem : NSObject {
}
@end
@implementation TmTrkTagItem {
}
@end
@implementation TmTrkOutlineViewDataSource {
NSMutableArray *_roots;
}
- (id)init {
printf("init\n");
self = [super init];
if (self) {
_roots = [[NSMutableArray alloc] init];
for (int i=0; i<3; i++) {
id item = [TmTrkTagItem new];
[_roots addObject:item];
}
printf("Created _roots %d.\n", (int)_roots.count);
}
return self;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
if (!item) {
printf("child: %d ofItem: %s\n", (int)index, [item description].UTF8String);
return _roots[index];
}
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
if (!item) return YES;
else return NO;
}
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
if (!item) return _roots.count;
else return 0;
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
NSString *val = @"Test Value";
return val;
}
@end
This is a new project, in Xcode 5.0.2, with ARC enabled.
Your data source might be getting released right after you create it since your app delegate doesn't maintain a strong reference to it, and NSOutlineView's dataSource is also a weak reference.