0

I don't know whether I have set this up incorrectly or not, but what I have done makes sense to me.

I have an NSTableView with two columns in it - a properties column on the left and a values column on the right. The values column contains NSComboBoxCells which are to be (dynamically) pre-populated with values relevant to the property in the left column.

The table is bound to an NSArrayController which references an array of objects. The object referenced has a number of properties defined, including one for the properties column (the property is called "name"), a value for the values column (called "value"), and a possibleValues property which returns the NSArray of available values dependent on the property.

This is all working correctly as long as the values cells are not being edited. As soon as they are edited, the drop-down of possible values is empty.

Having searched around, I found suggestions that the auto-complete checkbox should be checked for the Combo Box Cell, but checking it does not alter behaviour. I want the user to be able to tab from one table cell to the next, remaining in edit mode, and being able to make use of a pre-populated list of possible values.

On the object containing the data to be displayed in the table, I have declared the keyPathsForValuesAffecting... method too as such:

+ (NSSet *)keyPathsForValuesAffectingPossibleValues
{
    return [NSSet setWithObject:@"name"];
}

The detailed bindings are as such:

Property column is bound to arrayController

Value binding:

    Controller Key: arrangedObjects
    Model Key Path: name

Value column is bound to the same arrayController

Content binding:

    Controller Key: arrangedObjects
    Model Key Path: possibleValues

Value binding:

    Controller Key: arrangedObjects
    Model Key Path: value

NSComboBoxCell is not bound to anything. I have tried binding the content of the cell to the same as the value binding for the value column, but I get a list of objects - not the list of strings I create.

The header file for the object stored in the NSMutableArray which is bound to the NSArrayController basically looks something like:

#import <Foundation/Foundation.h>

@interface TableProperty : NSObject {
    NSString *name;
    NSString *value;
}

@property (readwrite, strong) NSString *name;
@property (readwrite, strong) NSString *value;
@property (readonly, assign) NSArray *possibleValues;

@end

The name and value properties are synthesised. The possibleValues property is a method which returns an array of NSString objects - the contents of which depend on the value of name.

I have put a break-point in the possibleValues method, which gets hit (twice) when the edit mode is started on the cell (and the correct NSArray is returned - both times). Once in edit mode, hitting the DOWN button on the keyboard pops up an empty box - this is the one which I would like to have populated with values. If the selection arrows to the right of the cell are clicked with the mouse, I have my list of correct values.

It is not possible for me to use a view-based table, as I need this application to function on Snow Leopard machines.

4

1 回答 1

1

NSComboBoxCell 从 NSTextFieldCell 继承自动完成功能,这需要您提供数据源。没有绑定可以为您实现功能。这样做的原因是该控件正在使用 NSStrings,并且您的列表可以包含多个具有相同字符串表示形式的项目。

于 2013-01-16T18:53:46.293 回答