我有一个 NSTableView 的表列绑定(bind)到 Interface Builder 中的 NSArrayController 。阵列 Controller 绑定(bind)到 Shared User Defaults Controller
对于Content Array
.我必须选择 Handles Content As Compound Value
使添加新对象起作用。不幸的是,当我 add:
时,这会禁用表格行的突出显示。数组的一个对象。对象已添加,但表格行未突出显示,您必须双击您认为该行能够对其进行编辑的位置。
我的目标是add:
使用数组 Controller 到 TableView 的一行;然后,让该行自动突出显示并可供用户编辑。
NSArrayController 的属性:
NSArrayController 的绑定(bind):
TableView 列的绑定(bind):
最佳答案
我找到的解决方法here为我工作。
你需要继承 NSArrayController 并实现你自己的 add: 方法
//
// MyArrayController.h
//
#import <AppKit/AppKit.h>
@interface MyArrayController : NSArrayController
@end
和
//
// MyArrayController.m
//
#import "MyArrayController.h"
@implementation MyArrayController
- (void)add:(id)sender {
[super add:sender] ;
[self performSelector:@selector(selectLastObject)
withObject:nil
afterDelay:0.0] ;
}
- (void)selectLastObject {
if ([self selectsInsertedObjects]) {
NSArray* arrangedObjects = [self arrangedObjects] ;
NSInteger nObjects = [arrangedObjects count] ;
if (nObjects > 0) {
[self setSelectionIndex:nObjects-1] ;
}
}
}
@end
关于interface-builder - 使用 NSArrayController 添加对象时使 NSTableView 行可编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12451811/