Bellow是我的didFinishPickingMediaWithInfo方法,我知道我有很多不必要的代码,保留,发布等...但这是我可以让它工作的方式,我害怕打破它试图优化它。
任何人都可以帮我脱掉不必要的东西,让这种方法干净吗?
此外,我有一个视图控制器,将加载4张照片(相机胶卷或相机),在选择器的第二或第三张照片选择后,应用程序崩溃或至少,我收到以下这些警报之一。我做错了什么?谢谢!
-2012-06-23 10:54:07.399 LookdoDia [6525:707]收到内存警告。
-wait_fences:未收到回复:10004003
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissModalViewControllerAnimated:YES];
UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
if(!img) img = [info objectForKey:UIImagePickerControllerOriginalImage];
uiimvImagem.image = [img retain];
uiimvImagem.alpha = 0;
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:img];
self.uiimvImagem = [tempImageView retain];
[tempImageView release];
CGRect frame = uiimvImagem.frame;
frame.size.width = 359;
frame.size.height = img.size.height / (img.size.width / 359);
uiimvImagem.frame = frame;
uisv1.showsVerticalScrollIndicator = NO;
uisv1.showsHorizontalScrollIndicator = NO;
uisv1.contentSize = CGSizeMake(uiimvImagem.frame.size.width, uiimvImagem.frame.size.height);
uisv1.maximumZoomScale = 3.0;
uisv1.minimumZoomScale = 0.8;
uisv1.clipsToBounds = YES;
uisv1.delegate = self;
[uisv1 addSubview:uiimvImagem];
[img release];
}
答案 0 :(得分:6)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
if(!img) img = [info objectForKey:UIImagePickerControllerOriginalImage];
uiimvImagem.image = img; //why bother?
uiimvImagem.alpha = 0; //why bother?
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:img];
self.uiimvImagem = tempImageView; //Make sure your self.uiimvImagem is a retained property! Also, don't forget to nil it out in your dealloc method
[tempImageView release];
CGRect frame = uiimvImagem.frame;
frame.size.width = 359;
frame.size.height = img.size.height / (img.size.width / 359);
uiimvImagem.frame = frame;
uisv1.showsVerticalScrollIndicator = NO;
uisv1.showsHorizontalScrollIndicator = NO;
uisv1.contentSize = CGSizeMake(uiimvImagem.frame.size.width, uiimvImagem.frame.size.height);
uisv1.maximumZoomScale = 3.0;
uisv1.minimumZoomScale = 0.8;
uisv1.clipsToBounds = YES;
uisv1.delegate = self;
[uisv1 addSubview:uiimvImagem];
[self dismissModalViewControllerAnimated:YES];
}
这应该会好一点 - 虽然我不确定其余部分是如何连接的(即属性声明,我不确定uisv1的分配位置。)还有一些看起来不对的东西 - 你将图像分配给图像视图,然后使用新分配的UIImageView运行整个图像。