iPhone,错误:无法设置对象 - 无论是readonly属性还是找不到setter

时间:2010-11-30 09:55:10

标签: iphone objective-c xcode

我知道在堆栈溢出时还有另外一个这样的问题,但我的问题来自我自己的类而不是UIButton。我的方法要复杂得多。第一个评论行有效。

@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
}

继承了它所称的功能。我试图重用代码并将事物保存在一个函数中。该函数使用addSubViewpresentModalViewController

@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
}

2 个答案:

答案 0 :(得分:3)

消息显示theControllerGettingStartedViewController没有属性。你的方法调用工作得很好。

self.theController = someObject与调用setter方法相同:[self setTheController:someObject]

属性自动生成那些getter和setter;所以如果你没有定义一个属性,它就不会创建一个setter,这就是你的问题。

将以下内容添加到头文件中:

@property (nonatomic, retain) UIViewController* theController;

并在您的实施文件中合成它:

@synthesize theController;

不要忘记在-dealloc方法中释放它,因为你告诉setter保留对象:

-(void) dealloc {
    [theController release];
    theController = nil;
}

答案 1 :(得分:0)

iPhone,错误:对象无法设置 - 无论是readonly属性还是没有setter发现错误,当你还没有合成它并仍然访问它的setter或/和getter方法时。

相关问题