我在故事板中添加了一个UITextView,在本例中,我为它创建了一个属性,并在UIView的子视图(称为FieldView)中进行了连接。这房子是这样的
@property (strong, nonatomic) UITextView * instructions;FieldView是viewController的一个属性。
@property (strong, nonatomic) IBOutlet FieldView *fieldView;当我想隐藏UITextView *指令并在viewController中使用代码时,我在.h文件中声明了这个属性,这样我最终可以在按下按钮时做到这一点。
self.fieldView.instructions.hidden = YES;但是,xCode给了我一个错误
illegal redeclaration of property in class extension FieldView, attribute must be readwrite while its primary must be readonly当我在.h和.m文件中添加readwrite时
@property (weak, nonatomic, readwrite) IBOutlet UITextView *instructions;
it said `perhaps you intended this to be a readwrite redeclaration of a readonly public property做我想做的事的正确方法是什么?
发布于 2014-04-18 16:30:42
要解决问题,需要在readonly文件中声明.h属性,在.m文件中声明readwrite属性:
//FieldView.h
@interface FieldView
@property (nonatomic, readonly, strong) UITextView *instructions;
@end
// FieldView.m
@interface FieldView()
@property (nonatomic, readwrite, strong) IBOutlet UITextView *instructions;
@end发布于 2016-01-12 15:11:13
我也有同样的问题,
如果在.h文件中声明了相同的name属性,并且您再次声明它的扩展名,那么您将得到这个错误。
因此,重命名属性名将解决此问题。
发布于 2021-07-02 19:34:29
对我来说,我不得不删除AppDelegate.h中的一个属性。
在此之前:
@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
@property (nonatomic, strong) UIWindow *window;之后:
@property (nonatomic, strong) UIWindow *window;https://stackoverflow.com/questions/23158056
复制相似问题