没有 Setter 分配给 属性 - cocoa 应用程序的方法
No Setter method for assignment to property - cocoa application
我是 objective-c 的新手,刚刚遇到了一个以前从未见过的错误。
我试图将文本字段单元格设置为 'selectable',但出现错误 "No Setter method 'setIsSelectable' for assignment to property."
这是 .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
在Objective-C中,以'is'开头的BOOL
属性通常只是属性的getter,而不是属性 ]本身。
这是一个约定。
仅供参考,您可以通过以下方式声明属性来自己完成此操作:
@property (nonatomic, getter=isAvaiable) BOOL available;
所以尝试设置上面的内容,而使用 isAvailable
是行不通的,因为它是 getter 方法,你不能设置 getter。
关于你的问题,
尝试将您的代码从 _textField.isSelectable = YES;
更改为以下任一代码,它应该可以工作。
_textField.selectable = YES;
[_textField setSelectable:YES];
祝你好运。
我是 objective-c 的新手,刚刚遇到了一个以前从未见过的错误。 我试图将文本字段单元格设置为 'selectable',但出现错误 "No Setter method 'setIsSelectable' for assignment to property."
这是 .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
在Objective-C中,以'is'开头的BOOL
属性通常只是属性的getter,而不是属性 ]本身。
这是一个约定。
仅供参考,您可以通过以下方式声明属性来自己完成此操作:
@property (nonatomic, getter=isAvaiable) BOOL available;
所以尝试设置上面的内容,而使用 isAvailable
是行不通的,因为它是 getter 方法,你不能设置 getter。
关于你的问题,
尝试将您的代码从 _textField.isSelectable = YES;
更改为以下任一代码,它应该可以工作。
_textField.selectable = YES;
[_textField setSelectable:YES];
祝你好运。