我想通過Apple文檔中的示例代碼設置一列非常基本的NSTableView。我正在以編程方式設置它,因爲可可綁定目前對我來說仍然有點像黑暗藝術,但是當我構建&運行時,我的應用程序中沒有任何數據。我的代碼中是否存在缺失? (我也迷上了通過Interface Builder中我的數據源和委託,因此它不能是無論是。)NSTableView沒有填充任何數據
接口文件
#import <Cocoa/Cocoa.h>
@interface RLTAppDelegate : NSObject <NSApplicationDelegate, NSTableViewDataSource, NSTableViewDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSScrollView *tableView;
@property (copy) NSArray *nameArray;
@end
實現文件
#import "RLTAppDelegate.h"
@implementation RLTAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
_nameArray = [[NSArray alloc] initWithObjects:@"Ryan", @"Steven", @"Scott", nil];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return _nameArray.count;
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSTextField *result = [tableView makeViewWithIdentifier:@"withoutIcon" owner:self];
result.stringValue = [self.nameArray objectAtIndex:row];
return result;
}
@end
這似乎是合乎邏輯的,但它並沒有造成很大的差異!我完全困惑,我必須誠實。 – Ryan
只是檢查tableview委託函數調用與否。 – Senthilkumar
我該怎麼做? – Ryan