#import <UIKit/UIKit.h> @interface DXWViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate> @property (retain, nonatomic) IBOutlet UIImageView *imageView; @property (retain, nonatomic) IBOutlet UIButton *Button; @property(retain,nonatomic) UIImage *image; - (IBAction)click:(id)sender; @end ViewController.m: [plain] view plaincopyprint? #import "DXWViewController.h" @interface DXWViewController () @end @implementation DXWViewController - (void)viewDidLoad { [super viewDidLoad]; } -(void)viewWillAppear:(BOOL)animated { self.imageView.image = self.image; } //加載成功 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { self.Image = [info objectForKey:UIImagePickerControllerEditedImage]; [picker dismissViewControllerAnimated:YES completion:nil]; } //取消 -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissViewControllerAnimated:YES completion:nil]; } - (void)dealloc { [_imageView release]; [_image release]; [_Button release]; [super dealloc]; } //打開圖庫獲取圖片 - (IBAction)click:(id)sender { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; picker.allowsEditing = YES; [self presentViewController:picker animated:YES completion:nil]; } }