Do the job does not work

I have this code that loads a new UIView (from the storyboard) when a button is clicked. The goPressed function starts when the button is pressed and calls the selectImage function. selectImage opens a UIImagePickerController and allows the user to select a photo. After the user selects the photo, the didFinishPickingMediaWithInfo delegate adds the selected image to the UIImageView.

In 'goPressed', after executing selectImage, it should execute Segue, for example, as // 1. But nothing happens. performSegueWithIdentifier doesn't seem to work. And if I do not call [self selectImage] before calling the performSegueWithIdentifier function, it works. Here is the code:

- (IBAction)goPressed:(id)sender {
    [self selectImage];
    [self performSegueWithIdentifier:@"lastView" sender:currentSender]; //1
}
-(void)selectImage
{
    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;

    // Delegate is self
    imagePicker.delegate = (id)self;

    // Allow editing of image ?
    imagePicker.allowsEditing=NO;


    // Show image picker
    [self presentModalViewController:imagePicker animated:YES];


}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    [[picker presentingViewController] dismissModalViewControllerAnimated:YES];


    lePreview.image= image;


}

, , performSegueWithIdentifier ? , , .

+3
1

, , , , , ? , ?

, , , segue , - " ".

segue , :

[[picker presentingViewController] dismissModalViewControllerAnimated:YES];

:

[[picker presentingViewController] dismissModalViewControllerAnimated:NO];

, segue "picker done finish" :

[self dismissModalViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:@"lastView" sender:self];
}];

, pickerdidfinish ( - , , :

//maintain the animation
[self dismissModalViewControllerAnimated:YES];

//slight pause to let the modal page dismiss and then start the segue
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

    //code to be executed on the main queue after delay

    [self performSegueWithIdentifier:@"lastView" sender:self];

});

, , segue, .

+13

All Articles