5

我对objective-c还很陌生,刚刚遇到了一个我以前从未见过的错误。我正在尝试将文本字段单元格设置为“可选”,但出现错误“没有用于分配给属性的 Setter 方法 'setIsSelectable'”。

这是 .h 和 .m 文件。谢谢。

DataPanel.h
#import <Cocoa/Cocoa.h>

@interface DataPanel : NSPanel
@property (weak) IBOutlet NSTextFieldCell *textField;

@end



DataPanel.m
#import "DataPanel.h"

@implementation DataPanel
@synthesize textField = _textField;

- (void) awakeFromNib{

_textField.stringValue = @"1.1 Performance standards The overall objective of       the performance standards in Section 1.1 is to provide acoustic conditions in schools that (a) facilitate clear communication of speech between teacher and student, and between students, and (b) do not interfere with study activities.";
_textField.isSelectable = YES;
}

@end
4

1 回答 1

24

在 Objective-C 中,BOOL以“is”开头的属性通常只是属性的 getter,而不是属性本身。
它是一个约定。

仅出于一般知识,您可以通过以下方式声明属性来自己这样做:
@property (nonatomic, getter=isAvaiable) BOOL available;

所以尝试设置上述,而使用isAvailable将不起作用,因为它是getter方法,你不能设置getter。

至于您的问题,
请尝试将您的代码从_textField.isSelectable = YES;以下任何一个更改,它应该可以工作。
_textField.selectable = YES;
[_textField setSelectable:YES];

祝你好运朋友。

于 2015-02-15T17:30:02.483 回答