I have a view A, a view B and a view C. The idea is : I'm presenting view B on view A, view B has a delegate in view A that performs a segue : view C.

My problem is I have the message "Attempt to present view B on view A while a presentation is in progress!".

I can make it work adding a delay in the method of view A that performs the segue, but isn't there a better way to make it work ?

In view A, the delegate method :

- (void)addItemViewController:(NSString *)string text:(NSString *)textfield{
    [self barcodeData:string type:1 :^(BOOL finished) {
        if(finished){
            [self performSegueWithIdentifier:@"viewC" sender:self];
        }
    }]; 
}

In view B

[self.delegate addItemViewController:saisieManuelleTextView.text text:nil];    

[self dismissViewControllerAnimated:NO completion:nil];
有帮助吗?

解决方案

Try invoking the delegate in the animation completion handler (some overlap in postings as redent84 also suggested this):

[self dismissViewControllerAnimated:YES completion:^{
    [self.delegate addItemViewController:saisieManuelleTextView.text text:nil];    
}];

That way you're still getting the benefits of the delegate and avoid the possibility of simultaneous view controller animations.

Better yet, if view A presents view B, then make viewA responsible for dismissing viewB as well, instead of having viewB dismiss itself. That way viewB doesn't have to know how it was presented in the first place:

- (void)addItemViewController:(NSString *)string text:(NSString *)textfield{
    [viewB dismissViewControllerAnimated:YES completion:^{
        [self barcodeData:string type:1 :^(BOOL finished) {
            if(finished){
                [self performSegueWithIdentifier:@"viewC" sender:self];
             }
         }];
    }];
}

其他提示

The problem that you are seeing is related to the animation of the transitions. You are trying to animate the transition from view A to view C while there's already a transition active from view B back to view A.

Try using the completion block of the dismissViewControllerAnimated method:

[self dismissViewControllerAnimated:YES completion:^{
    [self performSegueWithIdentifier:@"MySegue" sender:self];
}];

Or try disabling the animation of the transition from the view B to view A so it doesn't affect at all:

// For navigation controllers
[self.navigationController popViewControllerAnimated:NO];

// For modal controllers
[self dismissViewControllerAnimated:NO completion:nil];

EDIT:

You are presenting the new controller before dismissing the previous one, change the following lines:

[self.delegate addItemViewController:saisieManuelleTextView.text text:nil];    
[self dismissViewControllerAnimated:NO completion:nil];

to this:

[self dismissViewControllerAnimated:NO completion:nil];
[self.delegate addItemViewController:saisieManuelleTextView.text text:nil];    

Alternatively, you can maintain the animation using the completion block as described above:

[self dismissViewControllerAnimated:YES completion:^{
    [self.delegate addItemViewController:saisieManuelleTextView.text text:nil];    
}];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top