Adding a UIImagePickerController as a sub view

Discussion in 'iOS Programming' started by printf, Sep 18, 2010.

  1. printf macrumors regular

    Joined:
    Aug 27, 2008
    #1
    i have some sample code of adding a UIImagePickerController to the subview of a window within the AppDelegate (which works fine), but i want to perform this action for a view within my view controller. All the code I see online is the same as mine, but theirs doesn't explicitely call [view addSubview:imagePicker.view]. anyway, when i run the following it compiles and runs fine, but all i see is a white screen with a blue bar at the top, so i'm clearly doing something wrong.

    ViewController.h:
    Code:
    @interface ViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>{
    	UIView* uiView;
    	UIImageView *imageView;	
    	UIImagePickerController *imagePicker;
    }
    
    ViewController.m:
    Code:
    - (void)viewDidLoad {
        [super viewDidLoad];
    	
    	self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    	
    	imagePicker = [[UIImagePickerController alloc] init]; 
    	imagePicker.allowsImageEditing = YES;
    	imagePicker.delegate = self; 
    	imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    	
    	[self.view addSubview:imagePicker.view];
    }
    
    any ideas?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. printf thread starter macrumors regular

    Joined:
    Aug 27, 2008
    #3
    nope, no luck. it did produce a slightly different result (a completely white screen with no blue bar), but no image picker. any other ideas? could someone try that code and see if it works for them?
     
  4. printf thread starter macrumors regular

    Joined:
    Aug 27, 2008
    #4

Share This Page