I am trying to make NSTableDataSource compatible object and give this object to NSTableView as DataSource, however when table tries to display data, it crashes.
@interface NSArrayDataSource : NSObject{
NSArray* internalArray;
}
-(id) initWithArray: (NSArray*) objects;
-(int)numberOfRowsInTableView:(NSTableView *)aTableView;
-(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;
-(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;
@end
@implementation NSArrayDataSource
-(id) initWithArray: (NSArray*) objects{
if(self = [super init])
{
internalArray = [[NSArray alloc] initWithArray:objects];
}
return self;
}
-(int)numberOfRowsInTableView:(NSTableView *)aTableView{
return [internalArray count];
}
-(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex{
id obj = [internalArray objectAtIndex:rowIndex];
// when I debug, I get same pointers with invalid data
// each object has "name" message
// this following line gives invalid pointer and
// it crashes
return [obj name];
}
-(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex{
}
@end
Can anyone tell me what could be the problem?
Right now I have removed every release and dealloc messages from my class, so no object is removed, I have done retain message call everywhere when I transfer data.
NSArrayDataSource* nsds = [[NSArrayDataSource alloc] initWithArray: myArray];
[tableView setDataSource:nsds];
I have one doubt, does NSArray does call [retain] for every objects while creating new object or it is just storing pointer values?
Suppose my object's name is "SLProject" then when I debug, in init method I see values under debug window correctly but in tableView delegation method the internalArray's debugger displays object of type "NSKVONotifying_SLProject" and they point to invalid data, however the addresses are correct.