Ios 当访问UIButton以禁用它时发送到解除分配实例的消息

Ios 当访问UIButton以禁用它时发送到解除分配实例的消息,ios,objective-c,iphone,xcode7,Ios,Objective C,Iphone,Xcode7,这是我创建UIButton的代码 - (void) setNavButton { self->_newbutton = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *myImage = [UIImage imageNamed:@"New@3x.png"]; UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMa

这是我创建UIButton的代码

- (void) setNavButton
{
     self->_newbutton =  [UIButton buttonWithType:UIButtonTypeCustom];
     UIImage *myImage = [UIImage imageNamed:@"New@3x.png"];

     UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0, 46,57)] autorelease];

     CGContextRef context = UIGraphicsGetCurrentContext();
     CGContextSetAllowsAntialiasing(context, true);
     CGContextSetShouldAntialias(context, true);
     CGContextSetInterpolationQuality(context, kCGInterpolationHigh);

     [imageView.layer setMinificationFilter:kCAFilterTrilinear];
     [imageView.layer setAllowsEdgeAntialiasing:YES];
     CGRect imageRect = CGRectMake(0,0, imageView.bounds.size.width+10, imageView.bounds.size.height);

     UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, [UIScreen mainScreen].scale);

     [imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
     [myImage drawInRect:CGRectMake(0,12,myImage.size.width,myImage.size.height)];
     myImage = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();

     [imageView setImage:myImage];
     [self->_newbutton setImage:[imageView image] forState:UIControlStateNormal];
}
我已经为此创建了属性,并在同一个目录中访问它以禁用它。但当我这样做时,我会收到错误消息,并说“Message sent to a deallocated instance”。我使用下面的代码来禁用它

 [self->_newbutton setEnabled:No];

使用
\u新按钮生成按钮

_newbutton = [UIButton buttonWithType:UIButtonTypeCustom];
[_newbutton setImage:[imageView image] forState:UIControlStateNormal];
还可以使用新按钮设置图像

_newbutton = [UIButton buttonWithType:UIButtonTypeCustom];
[_newbutton setImage:[imageView image] forState:UIControlStateNormal];
然后将禁用设置为

[self._newbutton setEnabled:No];
希望它能帮助你。

谢谢

在课堂上为自己而不是自己提供任何理由。h UIButton*\u newbutton@属性(非原子,保留)UIButton*newbutton;只有一个附加对象有一个关于目标C点语法的阅读,它不是C++访问指针的方式。问题是自动调整新的按钮。在被调用之前,这个新按钮被重新设置。所以它变成了一个Zobie对象。所以导致了一个崩溃。谢谢你们的帮助…………问题是自动释放新按钮。在被调用之前,这个新按钮被重新设置。所以它变成了一个Zobie对象。所以我造成了一场车祸。非常感谢你。。。。。