我试图更好地理解可可绑定。我可以在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