Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-06-2009, 09:28 AM   #20 (permalink)
adeem
Tutorial Author
 
Join Date: Jun 2008
Location: Lahore, Pakistan
Posts: 34
Default

Quote:
Originally Posted by NewiPhoneDeveloper View Post
Hi there,

let me share the piece of code with you, that finally solved my memory issues!

Code:
//this is my ViewController.h

@interface myViewController: UIViewController <UIImagePickerControllerDelegate> {
UIImagePickerController *picker;
}

@property (nonatomic, retain) UIImagePickerController *picker;

- (IBAction)openPhotolibrary:(id)sender;
- (void)useImage:(UIImage *)image;

@end
Code:
//this is inside my ViewController.m
- (IBAction)openPhotolibrary:(id)sender {

	if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

                //Now this seems to do the trick. The picker only gets allocated once. Therefore no memory issues any longer!
                //Before I did it this way, my app crashed after picking 25 images. This one still was OK after picking about 50 images.
		if (picker == nil) {
			picker = [[UIImagePickerController alloc] init];
			picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
			picker.allowsImageEditing = YES;
			picker.delegate = self;
		}
		[self presentModalViewController:picker animated:YES];
	}
}

- (void)useImage:(UIImage *)image {
   //add code to use the picked image
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)CurrentPicker {
    //hide the picker if user cancels picking an image.
	[[CurrentPicker parentViewController] dismissModalViewControllerAnimated:YES];
}

- (void)dealloc {
    [picker release];
    [super dealloc];
}
Hope this helps.
Thanks it work for me!
adeem is offline   Reply With Quote
 

» Advertisements
» Online Users: 615
18 members and 597 guests
ADY, AragornSG, Dattee, denied, Duncan C, iDifferent, john love, kapps11, Keys, klrichner, mapiko, peppinoss, Punkjumper, Robiwan, sle39lvr, smithdale87, Speed, timle8n1
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,745
Threads: 89,201
Posts: 380,564
Top Poster: BrianSlick (7,129)
Welcome to our newest member, Ashleyk27
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:45 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.