Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-06-2009, 08:28 AM   #20 (permalink)
adeem
Tutorial Author
 
Join Date: Jun 2008
Location: Lahore, Pakistan
Posts: 32
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
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,888
Threads: 38,671
Posts: 169,755
Top Poster: smasher (2,553)
Welcome to our newest member, jackcohen
Powered by vBadvanced CMPS v3.1.0

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