ios - dismissViewControllerAnimated:completion: not executed -


when call dismissviewcontrolleranimated:completion: dismiss uiviewcontroller completion block never executed when corresponding view in middle of being animated onto screen (using presentviewcontroller:animated:completion:).

the uiviewcontroller not dissappear. dismissviewcontrolleranimated:completion: being ignored.

the following code simplified code example because original bigger. code have given below simulates use-case network communication error might trigger view popup whilst view being popped-up @ same time..

code example:

nslog(@"presenting view");  [self presentviewcontroller:changelocationviewcontroller animated:yes completion:^{     nslog(@"view done presenting"); }];  nslog(@"dismissing view");  [self dismissviewcontrolleranimated:no completion:^{     nslog(@"view done dismissing"); }]; 

log output is:

2013-08-28 16:14:12.162 [1708:c07] presenting view
2013-08-28 16:14:12.178 [1708:c07] dismissing view
2013-08-28 16:14:12.583 [1708:c07] view done presenting


know how dismiss uiviewcontroller in these circumstances?

thanks in advance.

the reason code snippet isn't working because completion block in these methods executed @ later time after animations have completed. can see in logs: "dismissing view" happens before "view done presenting". try instead:

nslog(@"presenting view");  [self presentviewcontroller:changelocationviewcontroller animated:yes completion:^{     nslog(@"view done presenting");     nslog(@"dismissing view");      [self dismissviewcontrolleranimated:no completion:^{         nslog(@"view done dismissing");     }]; }]; 

edit:

if need make sure view dismissed when network error happens, try setting boolean instance variable called networkerrorfound.

when finish network connection, set yes if error happens. use code:

[self presentviewcontroller:changelocationviewcontroller animated:yes completion:^{     nslog(@"view done presenting");     nslog(@"dismissing view");      if (self.networkerrorfound) {         [self dismissviewcontrolleranimated:no completion:^{             nslog(@"view done dismissing");         }];     } }]; 

that way, it'll wait until it's done presenting dismiss. need handle case error happens after animation done (for instance, slow connection fails), that's outside scope of question.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -