It doesn't matter what I return, the table view will display only display text that is manually set (the 'Title' of the NSTextField) in the .xib file. Please help me figure out what I'm doing wrong. Thanks.
My NSTableView only has 1 column.
Here is the code :
#import "DeviceSettingsController.h"
#import <ImageCaptureCore/ImageCaptureCore.h>
@interface DeviceSettingsController ()
@property (weak) IBOutlet NSTableView *tableViewScanners;
@property (weak) IBOutlet NSMatrix *checkBoxes;
@property NSMutableArray *availableScanners;
@property ICDeviceBrowser *deviceBrowser;
@end
@implementation DeviceSettingsController
- (void)viewDidLoad {
[super viewDidLoad];
_availableScanners = [[NSMutableArray alloc] init];
_deviceBrowser = [[ICDeviceBrowser alloc] init];
_tableViewScanners.delegate = self;
_tableViewScanners.dataSource = self;
_deviceBrowser.browsedDeviceTypeMask = ICDeviceTypeMaskScanner | ICDeviceLocationTypeMaskLocal | ICDeviceLocationTypeMaskShared | ICDeviceLocationTypeMaskBluetooth | ICDeviceLocationTypeMaskBonjour;
_deviceBrowser.delegate = self;
[_deviceBrowser start];
}
- (id)initWithMainView:(NSView *)_theView AndMainController:(NSViewController *)_theViewController AndNibName:(NSString *)nibName AndArgs:(NSArray *)_args {
self = [super initWithMainView:_theView AndMainController:_theViewController AndNibName:nibName AndArgs:_args];
return self;
}
- (void)deviceBrowser:(ICDeviceBrowser *)browser didAddDevice:(ICDevice *)device moreComing:(BOOL)moreComing {
[_availableScanners addObject:device];
[_tableViewScanners reloadData];
}
- (void)deviceBrowser:(ICDeviceBrowser *)browser didRemoveDevice:(ICDevice *)device moreGoing:(BOOL)moreGoing {
[_availableScanners removeObject:device];
[_tableViewScanners reloadData];
}
- (void)didRemoveDevice:(ICDevice *)device {
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [_availableScanners count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSString *retVal = [((ICScannerDevice *)[_availableScanners objectAtIndex:row]) name];
return retVal;
}
@end
Is the tableview content mode cell based or view based? I assume it is view based since you mention a xib, therefore instead of the objectValueForTableColumn(Cell Based) you have to use
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
Also see Apple Docs, so a typical implementation would be as follows
- (NSView *)tableView:(NSTableView *)tableView
viewForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)row {
// Retrieve to get the @"MyView" from the pool or,
// if no version is available in the pool, load the Interface Builder version
NSTableCellView *result = [tableView makeViewWithIdentifier:@"MyView" owner:self];
// Set the stringValue of the cell's text field to the nameArray value at row
result.textField.stringValue = [self.nameArray objectAtIndex:row];
// Return the result
return result;
}