У меня есть код, которому нужен доступ к NSArray для работы. У меня есть NSArray, который я использую с Core Data, и в нем будут данные, но я не уверен, как заставить мой NSArrayController обращаться к NSArray.
Я не могу просто объявить это в файле заголовка следующим образом: NSArray *objectArray;
, потому что он не знает, как или к чему NSArray
получить доступ. Как именно я получу доступ к NSArray, который я использую с Core Data?
Мой заголовочный файл:
#import <Cocoa/Cocoa.h>
@interface MyOutlineView : NSOutlineView {
NSArrayController* objectArray;
}
@end
Мой файл реализации:
#import "MyOutlineView.h"
@implementation MyOutlineView
- (void) outlineView: (NSOutlineView *) aView
willDisplayCell: (id) aCell
forTableColumn: (NSTableColumn *)aColumn
item: (id) anItem
{
id rootObj = anItem;
unsigned row = [aView rowForItem:anItem];
[aCell setDrawsBackground: YES];
while ([aView levelForRow:row] != 0) {
row --;
rootObj = [aView itemAtRow:row];
}
// The colours here are foul and ugly. Use something else, for
// God's sake!
if( [objectArray indexOfObject:rootObj] % 2 )
[aCell setBackgroundColor: [NSColor yellowColor]];
else
[aCell setBackgroundColor: [NSColor blueColor]];
}
@end