코코아 바인딩을 더 잘 이해하려고합니다. 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