我試圖更好地理解可可綁定。我可以在IB builder中獲得一個使用NSArrayController的基本表。我正在使用相同的項目並嘗試以編程方式連接綁定,但是沒有行出現。以編程方式綁定NSTableView
這是我的頭文件
@interface SBGoalDetailController : NSViewController <NSTableViewDelegate, NSTableViewDataSource>
@property (nonatomic, strong) NSManagedObjectContext *gdcManagedObjectContext;
@property (nonatomic, strong) NSArrayController *accountArrayController;
@property (weak) IBOutlet NSTableView *accountTable;
- (id)initWithContext:(NSManagedObjectContext *)context;
而且我實現文件
@implementation SBGoalDetailController
- (id)initWithContext:(NSManagedObjectContext *)context
{
self = [super initWithNibName:@"GoalDetailView" bundle:nil];
if (self) {
[self setGdcManagedObjectContext:context];
}
return self;
}
- (void)awakeFromNib
{
_accountArrayController = [[NSArrayController alloc] init];
[[self accountArrayController] setManagedObjectContext:_gdcManagedObjectContext];
[[self accountArrayController] setEntityName:@"Account"];
[[self accountArrayController] setAutomaticallyPreparesContent:YES];
[[self accountTable] bind:@"content" toObject:_accountArrayController withKeyPath:@"arrangedObjects" options:nil];
[[self accountTable] bind:@"selectionIndexes" toObject:_accountArrayController withKeyPath:@"selectionIndexes" options:nil];
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSView *returnView = [tableView makeViewWithIdentifier:@"AccountCell" owner:[tableView delegate]];
NSTextField* textField = [[returnView subviews] objectAtIndex: 0];
[textField bind: NSValueBinding
toObject: returnView
withKeyPath: @"objectValue.accountName"
options: nil];
return returnView;
}
上是缺少了哪一步我有什麼建議?
嘿,歡迎來到SO! – paulmelnikow 2013-04-25 21:05:27