[英]iPhone, error: object cannot be set - either readonly property or no setter found
I know there's another question like this on stack overflow, but my problem is from my own class not a UIButton. 我知道在堆栈溢出时还有另一个类似的问题,但是我的问题来自我自己的类而不是UIButton。 My method is a lot more complicated.
我的方法要复杂得多。 The first commented line works.
第一个注释行有效。
@implementation GettingStartedViewController
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
//[cui showHelpClickButtonAtIndex:buttonIndex:self.view:
//theController:FALSE:HelpPageGettingStarted];
// Error from this next line error: object cannot be set - either
//readonly property or no setter found
self.theController = [cui showHelpClickButtonAtIndex:buttonIndex:
self.view:theController:FALSE:HelpPageGettingStarted];
}
- (void)viewDidLoad {
[super viewDidLoad];
cui = [CommonUI alloc]; // Used for several functions
}
And heres the function it calls. 这是它调用的函数。 I've trying to reuse code and keep things in one function.
我试图重用代码并将其保留在一个函数中。 the function uses
addSubView
and presentModalViewController
. 该函数使用
addSubView
和presentModalViewController
。
@implementation CommonUI
-(UIViewController *)showHelpClickButtonAtIndex:(int)buttonIndex:
(UIView *)vw:(UIViewController *)vc:(BOOL)useNav:(HelpPage)page{
if (buttonIndex == CommonUIInfoHelpPagesBtnIdx) {
if (useNav == TRUE) {
// snip
} else {
vc = [[HelpViewController alloc] initWithNibName:@"HelpView"
bundle:nil onPage:page];
[vw addSubview:vc.view];
return [vc autorelease];
}
} else {
// Snip
}
// Snip
}
The message says that there is no property for theController
in GettingStartedViewController
. 该消息表明,
GettingStartedViewController
没有theController
属性。 Your method call works just fine. 您的方法调用工作正常。
self.theController = someObject
is the same as calling the setter method: [self setTheController:someObject]
self.theController = someObject
与调用setter方法相同: [self setTheController:someObject]
Properties automatically generate those getters and setters; 属性自动生成那些getter和setter。 so if you did not define a property, it is not going to create a setter and this is your problem here.
因此,如果您未定义属性,则不会创建设置器,这就是您的问题。
Add the following to your header file: 将以下内容添加到头文件中:
@property (nonatomic, retain) UIViewController* theController;
And synthesize it in your implementation file: 并将其合成到您的实现文件中:
@synthesize theController;
Do not forget to release it in the -dealloc
method, as you told the setter to retain the object: 不要忘记在
-dealloc
方法中释放它,就像您告诉setter保留对象一样:
-(void) dealloc {
[theController release];
theController = nil;
}
iPhone,错误:无法设置对象-当您尚未合成它并仍然访问其setter或/和getter方法时,出现readonly属性或找不到setter的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.