Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 Storyboard image picker not working :(

Im trying to set up an imagePicker in a new iOS7 Xcode project using storyboards but can't seem to find any examples online until I found the following code.

I've set it up so that when a button is pressed it uses a modal push thing to navigate to the view which has the class of "UIImagePickerController" which apparently calls in the image picker code.

However when the app is run it won't load anything up after clicking on allow the application to access your photos any chance of some help please?

Error screen shot grab: https://pbs.twimg.com/media/Bdy7v9JCAAABpvS.jpg:large

interface setup:

@interface ridecount_AddRide_ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>{

code:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    UIImagePickerController *controller = [segue destinationViewController];
    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    controller.delegate = self;
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [[self.view viewWithTag:100023] removeFromSuperview];
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(320/2-200/2, 10, 100, 100)];
    imageView.tag = 100023;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.image = image;
    [self.view addSubview:imageView];
}
like image 310
user3187832 Avatar asked Jan 15 '14 18:01

user3187832


1 Answers

Initialize the controller UIImagePickerController *controller = [[segue destinationViewController] init];

like image 110
Matt Avatar answered Oct 01 '22 21:10

Matt