开发者

Why am I getting memory errors using a UIImagePickerController?

When I load up my UIImagePickerController, I am getting:

warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3 (8F190)/Symbols/System/Library/Frameworks/IOKit.framework/IOKit (file not found).
warning: Tried to remove a non-existent library: /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3 (8F190)/Symbols/System/Library/Frameworks/IOKit.framework/IOKit
2011-06-12 20:21:23.210 myapp[919:707] Received memory warning. Level=1

When I take snapshot, I get a memory warning level 2.

Here is my code:

#import <UIKit/UIKit.h>


    @interface SnapShotViewController : UIViewController<UINavigationControllerDelegate,UIImagePickerControllerDelegate> {

        IBOutlet UIButton *button;
        IBOutlet UIImageView *image;
        UIImagePickerController *imgPicker;

    }

    - (IBAction)grabImage;
    - (IBAction)useImage;

    @property (nonatomic, retain) UIImagePickerController *imgPicker;
    @property (nonatomic,retain)UIImageView *image;
    @property (nonatomic,retain)UIButton *button;

    @end



    #import "SnapShotViewController.h"


    @implementation SnapShotViewController

    @synthesize imgPicker, image, button;


    - (IBAction)grabImage{

        [self presentModalViewController:self.imgPicker animated:YES];

    }

    - (IBAction)useImage{
        NSLog(@"entering useImage...");

        if (image==nil) {
            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"No Image Selected" 
                                                                     delegate:nil 
                                                            cancelButtonTitle:@"OK" 
                                                       destructiveButtonTitle:nil 
                                                            otherButtonTitles:nil];

            [actionSheet showInView:[[self view]window]];
            [actionSheet autorelease];
        }


    }



    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
        [image setImage:img];
        [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    }

    // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    /*
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization.
        }
        return self;
    }
    */


    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];


        self.imgPicker = [[UIImagePickerController alloc] init];
        //self.imgPicker.allowsImageEditing = YES;
        imgPicker.delegate =self;

        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])  {

            self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        }else

        self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }


    /*
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations.
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    */

    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];

        // Release any cached data, images, etc. that aren't in use.
    }

 - (void)viewDidUnload {
    [super vi开发者_JS百科ewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

    self.image = nil;
    self.button = nil;


}


- (void)dealloc {

    [imgPicker release];
    [image release];
    [button release];

    [super dealloc];
}


    @end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜