これについて多くの質問があるようですが、この作業を行うのに何も役に立ちませんでした。3 つの列 (適切な識別子が設定されている) を持つ NSTableView と、ShortcutsTableController という名前のクラスを持つペン先があります。nib には、クラス値 ShortcutsTableController を持つ NSObject があります。また、通常どおり NSTableView をコントローラーに接続しました。
これはヘッダーShortcutsTableController.h
です。
#import <Cocoa/Cocoa.h>
@interface ShortcutsTableController : NSObject <NSTableViewDataSource> {
IBOutlet NSTableView *shortcutsTable;
NSMutableArray *shortcutsList;
}
- (int) numberOfRowsInTableView: (NSTableView*) tableView;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;
@property (assign) IBOutlet NSTableView *shortcutsTable;
- (void)setUpTable;
@end
これが実装ファイルですShortcutsTableController.m
。
#import "ShortcutsTableController.h"
@implementation ShortcutsTableController
@synthesize shortcutsTable;
- (void)setUpTable {
shortcutsList = [[NSMutableArray alloc] init];
NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:
@"blabla", @"nameColumn",
@"Bla bla bla", @"shortcutColumn",
@"Ribla", @"actionColumn", nil];
[shortcutsList addObject:dict1];
[shortcutsTable setDataSource:self];
[shortcutsTable reloadData];
}
-(int) numberOfRowsInTableView: (NSTableView *) tableView {
return [shortcutsList count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row {
if (row != -1)
return [[shortcutsList objectAtIndex:row] objectForKey:[tableColumn identifier]];
return nil;
}
@end
しかし、ビルドしようとすると、NSTableView に何も表示されません。エラーも警告もありません。Delegate Class Method 内から setUpTable を呼び出すことに注意してくださいawakeFromNib
。
私が間違っていることはありますか?助けてくれてありがとう。
――アルベ
アップデート。@property (assign) IBOutlet NSTableView *shortcutsTable;
ヘッダーと@synthesize shortcutsTable;
実装に行を追加しました。何も変わりません。:(