我有一个NSTokenField,不会让我编辑它。不可编辑,我的意思是它被卡在占位符文本上并点击它不允许我输入它。有谁知道为什么会这样?
为了澄清,这是我的委托代码。我将NSTokenField连接到IBOutlet,并将令牌字段连接到InputFieldDelegate对象(蓝盒事物)。
InputFieldDelegate.h:
@interface InputFieldDelegate : NSObject <NSTokenFieldDelegate> {
NSTokenField *inputTokenField;
}
@property (assign) IBOutlet NSTokenField *inputTokenField;
- (NSArray *)tokenField:(NSTokenField *)tokenFieldArg
completionsForSubstring:(NSString *)substring
indexOfToken:(NSInteger)tokenIndex
indexOfSelectedItem:(NSInteger *)selectedIndex;
- (id)tokenField:(NSTokenField *)tokenField
representedObjectForEditingString:(NSString *)editingString;
@end
InputFieldDelegate.m:
#import "InputFieldDelegate.h"
@implementation InputFieldDelegate
@synthesize inputTokenField;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
inputTokenField = [[NSTokenField alloc] init];
[inputTokenField setDelegate:self];
}
- (NSArray *)tokenField:(NSTokenField *)tokenFieldArg
completionsForSubstring:(NSString *)substring
indexOfToken:(NSInteger)tokenIndex
indexOfSelectedItem:(NSInteger *)selectedIndex {
return [NSArray arrayWithObject: nil];
}
- (id)tokenField:(NSTokenField *)tokenField
representedObjectForEditingString:(NSString *)editingString {
return editingString;
}
@end