我有NSTableView
一个单列。此列在 Interface Builder 中选中了“可编辑”,但双击表格视图中的单元格没有任何作用。我已经确认(-tableView:viewForTableColumn:row:
通过检查[tableColumn isEditable]
)表列设置了可编辑标志。什么会阻止该列被编辑isEditable == YES
?
有人建议我包含我的数据源和委托代码。dataArray
是存储NSManagedObject
子类对象的属性。listPopupButton
选择要在一个NSTableView
可以显示不同实体的实体中查看的实体,所有这些实体都只有一个名称属性(如nameOnlyItems
返回这些实体的数组的方法所示)。
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [[self dataArray] count];
}
- (NSView *)tableView:(NSTableView *)tableView
viewForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)row {
NSTableCellView *cellView;
NSNumber *index = [NSNumber numberWithInteger:[[self listPopupButton] indexOfSelectedItem]];
if ([[self nameOnlyItems] containsObject:index]) {
CVCAbstractEntity *entity = [[self dataArray] objectAtIndex:row];
NSString *name = [entity name];
cellView = [tableView makeViewWithIdentifier:@"nameOnly" owner:self];
[[cellView textField] setStringValue:name];
} else if ([index integerValue] == CVCListPopUpIndexPublishers) {
CVCPublisher *publisher = [[self dataArray] objectAtIndex:row];
NSString *identifier = [tableColumn identifier];
NSString *content;
content = [[publisher valueForKeyPath:identifier] description];
if ([identifier containsString:@"year"] && [content isEqualToString:@"0"]) {
content = @"";
}
cellView = [tableView makeViewWithIdentifier:identifier owner:self];
[[cellView textField] setStringValue:content ? content : @""];
} else if ([index integerValue] == CVCListPopUpIndexSeries) {
CVCSeries *series = [[self dataArray] objectAtIndex:row];
NSString *identifier = [tableColumn identifier];
NSString *content;
content = [[series valueForKeyPath:identifier] description];
if ([identifier containsString:@"year"] && [content isEqualToString:@"0"]) {
content = @"";
}
cellView = [tableView makeViewWithIdentifier:identifier owner:self];
[[cellView textField] setStringValue:content ? content : @""];
}
return cellView;
}
- (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors {
NSMutableArray *mutableDataArray = [[self dataArray] mutableCopy];
[mutableDataArray sortUsingDescriptors:[tableView sortDescriptors]];
[self setDataArray:mutableDataArray];
[[self nameOnlyTableView] reloadData];
}