Пожалуйста, используйте этот код:
Делегат приложения // .h
#import <UIKit/UIKit.h>
@interface MyProjectAppDelegate : NSObject <UIApplicationDelegate> {
UIImagePickerController *image_picker;
UIWindow *window;
UINavigationController *navigationController;
}
@property(nonatomic, retain) UIImagePickerController *image_picker;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
-(void)initializeImagePickerView;
@end
// .m
#import "MyProjectAppDelegate.h"
#import "RootViewController.h"
@implementation MyProjectAppDelegate
@synthesize window;
@synthesize navigationController,image_picker;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self initializeImagePickerView];
// Set the navigation controller as the window's root view controller and display.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
-(void)initializeImagePickerView
{
// Picker View
self.image_picker = [[UIImagePickerController alloc] init];
self.image_picker.allowsImageEditing = YES;
}
- (void)dealloc {
[image_picker release];
[navigationController release];
[window release];
[super dealloc];
}
@end
// RootView Controller // .h
#import <UIKit/UIKit.h>
#import "MyProjectAppDelegate.h"
@interface RootViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>{
MyProjectAppDelegate *appDelegate;
}
-(IBAction)btnPhotoPressed:(id)sender;
@end
// .m
#import "RootViewController.h"
@implementation RootViewController
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (MyProjectAppDelegate *)[[UIApplication sharedApplication] delegate];
}
-(IBAction)btnPhotoPressed:(id)sender
{
appDelegate.image_picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
appDelegate.image_picker.delegate=self;
[self presentModalViewController:appDelegate.image_picker animated:YES];
}
#pragma mark UIImagePickerController delegate
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *imgCapturePhoto = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// You can use image here
[self dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
- (void)dealloc {
[super dealloc];
}
Это определенно поможет вам.