我在設置圖像時出現問題。我有一個委託人告訴我什麼時候從imagePickerController獲取圖像。它將它發送給所有者控制器,然後嘗試在另一個控制器上設置圖像。這一切似乎都應該起作用......但每當我看到視圖時,圖像就不存在了。下面的代碼:setImage不起作用
// 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 ::',你是積極的'圖像'不是'無'?你正在檢查' - didAcquirePicture:'中的'nil'(或者更確切地說'Nil'),但是你甚至不會給自己一個'NSLog'來驗證是否正在執行所需的代碼。在繼續之前,我會仔細檢查一下「無」的值。 –
僅供參考,甚至會擴展到相同的東西,Nil旨在表示NULL,而不是對象...使用nil代替,以提高可讀性... – Macmade
不確定圖像問題,但我在代碼中看到一些問題。在你實現的dealloc方法中,釋放你的實例變量,然後調用[super dealloc]。如果您沒有將@EditView作爲@property(retain等)聲明,那麼下一部分不是問題。 self.photoEditView = [[PhotoEditViewController alloc] init]將會泄漏,如果該屬性在設置時保留它...你可以使用self.photoEditView = [[[PhotoEditViewController alloc] init] autorelease];如果屬性設置爲保留,則避免內存泄漏 –