원래 콘센트를 통해 내 NSTableView를 채우고 컨트롤러 클래스에 테이블의 dataSource를 설정했습니다. 내 응용 프로그램에서 열 정렬 할 수 있도록 NSArrayController 사용하여 전환 할 노력하고있어.NSArrayController를 통해 코어 데이터에서 NSTableView를 채우려면 어떻게해야합니까?
IB에서는 Array Controller 개체를 추가했습니다. Sort Descriptors 바인딩을 Shared User Defaults Controller에 연결하여 정렬 된 열을 내 앱 시작 사이에 유지할 수 있습니다. 배열 테이블에있는 각 열의 배열 컨트롤러에 바인딩 된 컨트롤러 키가 'arrangedObjects'로 설정되고 모델 키 경로가 렌더링되어야하는 필드의 이름으로 설정됩니다.
내 데이터가 핵심 데이터에서 나오고 표시하려고하는 엔티티가 다른 엔티티와 관계가 있습니다. 두 번째 엔티티의 속성은 테이블 열 중 하나의 값으로 표시되어야합니다. 누구나 내가 여기 놓친 것에 대해 어떤 생각/제안을 가지고 있니?
MainWindowController.h
#import <Cocoa/Cocoa.h>
#import "Notification.h"
@class AppDelegate;
@interface MainWindowController : NSWindowController <NSTableViewDataSource, NSTableViewDelegate> {
AppDelegate <NSApplicationDelegate> *appDelegate;
}
//@property NSMutableArray *userNotifications;
@property (weak) IBOutlet NSTableView *notificationsTable;
@property (weak) IBOutlet NSArrayController *notificationsController;
@end
MainWindowController.m
#import "AppDelegate.h"
#import "MainWindowController.h"
#import "Utils.h"
@implementation MainWindowController
//@synthesize userNotifications;
@synthesize notificationsTable;
@synthesize notificationsController;
- (void) doubleClick:(id)sender
{
NSInteger row = [notificationsTable clickedRow];
// Notification *clickedNotification = [userNotifications objectAtIndex:row];
// Notification *clickedNotification =
// [appDelegate redirectToBrowser:clickedNotification];
}
- (id) initWithWindowNibName:(NSString *)windowNibName
{
self = [super initWithWindowNibName:windowNibName];
if (self) {
// userNotifications = [[NSMutableArray alloc] init];
appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
[notificationsController setManagedObjectContext:[appDelegate managedObjectContext]];
[notificationsController setEntityName:@"Notification"];
[notificationsController setAutomaticallyPreparesContent:YES];
[notificationsController fetch:self];
[notificationsTable reloadData];
}
return self;
}
- (void)windowDidLoad
{
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
[notificationsTable reloadData];
}
- (void)awakeFromNib
{
[notificationsTable setTarget:self];
[notificationsTable setDoubleAction:@selector(doubleClick:)];
}