0

I'm using the Custom Picker by ray, when I press a button a picker is pop-ups then when image is chosen it will dismiss the picker and displayed the image in UIImageView. I put in the viewWillAppear but when I go to another ViewController the image chosen disappears. How to maintain the chosen in UIImageView to be displayed even after going to different View Controllers, only will it change if another image is chosen again.

- (void)viewWillAppear:(BOOL)animated {

    secondView.image = _imagePicker.selectedImage;
}

- (IBAction)chooseCustomImageTapped:(id)sender {
    _imagePicker = [[CustomImagePicker alloc] init];
    _imagePicker.title = @"Choose Custom Image";
   for(int i = 0; i <= 10; i++) 
    { 
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDir = [paths objectAtIndex:0];
        NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", i]]; 

        if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){ 
            [_imagePicker addImage:[UIImage imageWithContentsOfFile:savedImagePath]]; 

        } 
    } 
     [self presentModalViewController:_imagePicker animated:NO];
}
4

3 に答える 3

0

I think you should take your image in UIImage object just after selection done UIImage *image = _imagePicker.selectedImage;, and retain it till next change. Then set that image to your image view secondView.image = image;.

于 2012-06-20T06:23:30.550 に答える
0

Did you alloc a new view controller when you go to the specified view controller? If so, when you go to a new view controller, you alloc it, so all the datas has been initalized.

于 2012-06-20T06:40:07.447 に答える
0

use the pickerview delegate function.

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
         // put your logic here.

 NSUserDefaults *udf=[NSUserDefaults standardUserDefaults];
    [udf setObject:@"Imagename" forKey:@"LastSelectImage"];

    }

accordingly your image has change your image name here.

于 2012-06-20T06:44:46.867 に答える