Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BarryK88

macrumors member
Original poster
Mar 1, 2011
31
0
I'm using an imagePickerController to replace my existing images inside my view. The function works within the same IB-file. However I'd like to load the chosen image in another IB-File as well. I think that the solution is to give a name to the image when saved. After it is saved I'd like to call the image (by name) from my memory within my other IB-file.

Here's a snippit of code I'm using within the photopicker IB-file

Code:
-(IBAction)setPhoto{

    image1.image = fotoView.image;
}

-(IBAction)getCameraPicture:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsImageEditing = YES;
    picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera :
    UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController: picker animated:YES];
    [picker release];
}

-(IBAction)selectExitingPicture
{
    if([UIImagePickerController isSourceTypeAvailable:
        UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *picker= [[UIImagePickerController alloc]init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
}

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

    fotoView.image = image;

    NSData* imdata =  UIImagePNGRepresentation ( image );
    UIImage* im8 = [UIImage imageWithData:imdata];
    UIImageWriteToSavedPhotosAlbum(im8, nil, nil, nil);
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
    [picker dismissModalViewControllerAnimated:YES];
}

within my other class I'd like to call this image by means of:

Code:
if (#some condition){
        UIImage *img = [UIImage imageNamed:@"Name of the image.png"];
        [image1 setImage:img];

}

How will I be able to give a name to the saved image and call it afterwords within another class?

Help is greatly appreciated
 
Image named can only be used to load images from your own applications bundle. The "name" is the file name. As you are saving to the photos album you cannot retrieve the image by "name".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.