0

我们在 init 方法中创建了按钮,我们创建了两个 Uiimage 对象并创建了 Boolean

      if(!isHint)
      {
          [hintBtn setImage:hintBtnImage forState:UIControlStateNormal];
      }
      else
      {
          [hintBtn setImage:hintBtnImagex forState:UIControlStateNormal]; 
      }   
      hintBtn =[[UIButton alloc]initWithFrame:CGRectMake(794, 144, hintBtnImage.size.width, hintBtnImage.size.height)]; 
      [hintBtn setImage:hintBtnImage forState:UIControlStateNormal];
      [hintBtn addTarget:self action:@selector(showHint) forControlEvents:UIControlEventTouchUpInside];

当用户点击 tableview 单元格时,我们会更改布尔变量并设置图像。就像下面的代码

    if(wrongx==1)
    {
        NSLog(@"the wrong x is %i",wrongx);    
        isHint = NO;
        [hintBtn setImage:hintBtnImage forState:UIControlStateNormal];
    }  

但是当我第一次点击应用程序时它正在工作但第二次我收到以下错误

[UIImage retain]: message sent to deallocated instance

请回复我的帖子。在此先感谢

4

1 回答 1

0

你在哪里分配了“hintBtnImage”对象。我认为你试图在没有分配的情况下访问“hintBtnImage”。

hintBtn =[[UIButton alloc]initWithFrame:CGRectMake(794, 144, hintBtnImage.size.width, hintBtnImage.size.height)];

需要小代码修改,与解决你的问题无关,上面应该是这样的

hintBtn =[[UIButton alloc]initWithFrame:CGRectMake(794, 144, hintBtnImage.size.width, hintBtnImage.size.height)];
      if(!isHint)
      {
          [hintBtn setImage:hintBtnImage forState:UIControlStateNormal];
      }
      else
      {
          [hintBtn setImage:hintBtnImagex forState:UIControlStateNormal]; 
      }   
于 2012-05-30T06:10:11.607 回答