私は現在コントローラのinit
メソッドでNSMutableArrayの1つのエントリを初期化するコントローラ(MVCデザインパターン)を介してNSTableViewを設定しています。NSTableViewに入力する方法は?
はどのようになります。
- は人の列が
- オブジェクトである私NSMutableArrayのを移入私の代わりに私の基本クラスの私の
mainViewDidLoad
方法でNSMutableArrayのを移入する必要がありますか?私はこれのための例やリソースが見つかりませんでした。
モデル(Person.m)
#import "Person.h"
@implementation Person
@synthesize name;
@synthesize gender;
- (id)init
{
self = [super init];
if (self) {
name = @"Bob";
gender = @"Unknown";
}
return self;
}
- (void)dealloc
{
self.name = nil;
self.gender = nil;
[super dealloc];
}
@end
コントローラ(PersonController.m)
#import "PersonController.h"
#import "Person.h"
@implementation PersonController
- (id)init
{
self = [super init];
if (self) {
PersonList = [[NSMutableArray alloc] init];
// [personList addObject:[[Person alloc] init]];
//
// [personTable reloadData];
}
return self;
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [personList count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
Person *person = [personList objectAtIndex:row];
NSString *identifier = [tableColumn identifier];
return [person valueForKey:identifier];
}
- (void)dealloc
{
[super dealloc];
}
@end
ベースファイル(Main.h):
#import "Main.h"
@implementation Main
- (void)mainViewDidLoad
{
}
@end
申し訳ありませんが、私は自分のイニシャライザーコードを含めるべきでした。わかりやすくするために、Person.hをPerson.mに置き換えたときの更新を参照してください。 – Coderama