ios - Able to dismiss entire stack of view controllers except for the controller calling dismiss -
i start uitabbarcontroller (vc1)
i present uiviewcontroller(vc2) on top of , set variable named parentcontroller self:
let logincontroller = logincontroller() dispatchqueue.main.async { self.present(logincontroller, animated: false, completion: { // once presented, set parentcontroller = self logincontroller.parentcontroller = self }) } i continue present third uiviewcontroller(vc3) on top of vc2 when user taps "login email button":
let withemailcontroller = withemaillogincontroller() withemailcontroller.parentcontroller = self present(withemailcontroller, animated: true, completion: nil) after signing email, present fourth uiviewcontroller(vc4) user can pick profile picture
let profilepicturepickercontroller = profilepicturepickercontroller() profilepicturepickercontroller.parentcontroller = self present(profilepicturepickercontroller, animated: true, completion: nil) after user has picked profile picture call code in vc4 in attempt dismiss vc2, vc3, , vc4 function in vc2:
parentcontroller?.parentcontroller?.handledismiss() where handledismiss in vc2 simply:
func handledismiss() { // progress maintabbarcontroller parentcontroller?.progresswithloggedinuser() // dismiss logincontroller self.dismiss(animated: true) { // things in here aren't relevant question } } the problem: when function belonging vc2 named handledismiss called vc2, works fine , vc2 dismissed (vc3 , vc4 not dismissed because have not been presented yet). however, when handledismiss called vc4 above, vc3 , vc4 dismissed. vc2 remains. vc1,2,3,4 in same stack, understanding.
what have tried: putting present/ dismiss commands in dispatchqueue.main.async {code}. calling parentcontroller?.parentcontroller?.dismiss(animated: true, completion: nil) directly in vc4 has same error. calling handledismiss() vc2 make sure works properly
where else have looked: dismiss more 1 view controller simultaneously, dismissing presented view controller. feel setting parentcontroller variables same using presentingviewcontroller
okay turns out re-reading apple documentation idea
the answer: understanding calling dismiss on uiviewcontroller 2 different things depending on whether controller has children (controllers presented on top of it). if call dismiss on top view controller i.e. topcontroller.dismiss(animated: true){code} dismiss top controller expected. if, however, call dismiss on controller has children, dismiss children of controller, not controller itself. top child 1 animates.
if calling dismiss in stack, must call on parent of child want dismiss: parentcontroller.dismiss(animated: true){code}
implemented solution: function handledismiss() has been moved vc1 , fixes everything.
Comments
Post a Comment