我看到有很多关于此的问题,但没有任何帮助我得到这项工作。 我有一个带有三列的NSTableView(带有正确的标识符集)和一个名为ShortcutsTableController的类。在笔尖我有一个NSObject与类值ShortcutsTableController。我也像往常一样将NSTableView连接到我的控制器。无法获得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中没有任何东西出现时。没有错误,没有警告。请注意,我从代理类方法awakeFromNib
中调用setUpTable。
有什么我做错了吗?谢谢你的帮助。
-Albé
UPDATE。在头文件中增加了行@property (assign) IBOutlet NSTableView *shortcutsTable;
,在执行中增加了@synthesize shortcutsTable;
。没有什么变化。 :(
这是什么'的NSLog(@ “%@”,shortcutsTable);'产生'setUpTable '? – 2009-12-04 15:33:47
(null)。 :O无法理解这个:( – Donovan 2009-12-04 17:11:44