gpt4 book ai didi

ios - setImage 不工作

转载 作者:行者123 更新时间:2023-11-28 23:11:12 29 4
gpt4 key购买 nike

我在设置图像时遇到问题。当从 imagePickerController 中获取图像时,我有一个代表告诉我。它将它发送到所有者 Controller ,然后我尝试在另一个 Controller 上设置图像。一切似乎都应该正常工作……但是每当我显示 View 时,图像都不存在。这是代码:

// this gets called when an image has been chosen from the library or taken from the camera
// it is in the viewController in charge of grabbing an image (.m file)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
if(self.delegate)
{
[self.delegate didAcquirePicture:image];
}
}


//This is in the controller .m file
- (void)didAcquirePicture:(UIImage *)picture
{
if(picture != Nil)
{
self.photoEditView = [[PhotoEditViewController alloc] init];
[self.photoPicker.imagePickerController dismissModalViewControllerAnimated:NO];
[self.photoEditView.imageView setImage:picture];
[self presentModalViewController: self.photoEditView animated:NO];

}
}

//this is the photoEditViewController .h
#import <UIKit/UIKit.h>

@class PhotoEditViewController;

@protocol PhotoEditViewControllerDelegate
@end


@interface PhotoEditViewController : UIViewController {
IBOutlet UIImageView *imageView;
}

@property (retain) UIImageView *imageView;


@end

//this is the photoEditView .m file
#import "PhotoEditViewController.h"

@implementation PhotoEditViewController

@synthesize imageView;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)dealloc {
[super dealloc];
[imageView dealloc];
}

@end

最佳答案

看起来有可能在您关闭 imagePickerController 时释放图像,然后再将其分配给 imageView。如果是这样,你可以修复它

[[图片保留]自动释放];

如前所述,针对 nil 而不是 Nil 进行测试。此外,最好使用 [self.delegate respondsToSelector: @selector(didAcquirePicture)]; — 请记住将消息发送到 nil 是安全的。

关于ios - setImage 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8219586/

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