在我的iPhone應用程序上,我有兩個viewController(firstViewController,secondViewController),firstViewController用戶可以從相機膠捲中選擇一張照片,然後將其顯示在一個imageView中,但是我還需要顯示它在secondViewController中,但不知道如何。跨視圖控制器傳輸圖像
你能不能也請解釋深入你的答案,因爲我是相當新的目標-C
這裏是我的代碼:
firstViewController.h
#import <UIKit/UIkit.h>
@interface firstViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIImageView *theImageView;
}
@property (nonatomic, retain) IBOutlet UIImageView *theImageView;
-(IBAction)selectExistingPicture;
@end
firstViewController.m
#import "firstViewController.h"
#import "secondViewController.h"
@implementation firstViewController
@synthesize theImageView
-(IBAction) selectExistingPicture
{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
theImageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
-(IBAction)switchSecondViewController {
SecondViewController *viewcontroller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:viewcontroller animated:YES];
[viewcontroller release];
}
// Default Apple code
@end
secondViewController沒有太多,所以我不打擾發佈該代碼。
如果您的圖像存儲在應用程序的「文檔目錄」中,則可以將圖像名稱傳遞給下一個類,您可以在其中使用它來顯示圖像。 – rptwsthi