Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please use this code :</p> <p>App Delegate // .h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface MyProjectAppDelegate : NSObject &lt;UIApplicationDelegate&gt; { 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 </code></pre> <p>// .m</p> <pre><code>#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 </code></pre> <p>//RootView Controller // .h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "MyProjectAppDelegate.h" @interface RootViewController : UIViewController &lt;UIImagePickerControllerDelegate,UINavigationControllerDelegate&gt;{ MyProjectAppDelegate *appDelegate; } -(IBAction)btnPhotoPressed:(id)sender; @end </code></pre> <p>// .m</p> <pre><code>#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]; } </code></pre> <p>This will definitely help u. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload