gpt4 book ai didi

iPhone 应用程序因 __NSCFType 设置图像 :forState 而崩溃

转载 作者:行者123 更新时间:2023-12-02 00:37:06 28 4
gpt4 key购买 nike

我有一个应用程序,可以从相机捕获图像并将其设置为按钮。

因此,从相机捕获图像并点击使用按钮后,我的应用程序因 [NSCFType setImage:forstate] 无法识别的实例而崩溃

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *resizeImage = [image imageWithImage:image scaledToSize:CGSizeMake(320, 480)];

//convert the selected image to NSData
toShowFullImage = UIImageJPEGRepresentation(resizeImage, 0.8);

//retain it for further use
[toShowFullImage retain];

//set the selected image to button

UIImage *newimage=[image imageScaleAndCropToMaxSize:CGSizeMake(75, 75)];

[button setImage:newimage forState:UIControlStateNormal];
}

此崩溃发生在 iOS 6.0.1 中,并出现 Abort trap 6 错误

最佳答案

我认为问题在于当您设置已经发布的按钮的背景图像时。

解决此问题的可能方法:

  1. 当您将按钮添加到 View 时,您调用了[button release];
  2. 您使用 buttonWithType: 等工厂方法创建了按钮

可能的解决方案:

  1. 设置查看后不要调用release。
  2. 如果您使用 buttonWithType: 创建按钮,则只需保留该按钮
  3. 使用标签设置图像。

当您添加按钮时,设置一个标签,例如:

button.tag = 7;
[self.view addSubview:button];

并将图像设置为:

 [[self.view viewWithTag:7] setImage:newimage forState:UIControlStateNormal];

关于iPhone 应用程序因 __NSCFType 设置图像 :forState 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13507337/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com