Our app starts from the start to the main page. A viewcontroller sequence is constructed by Presentviewcontroller, similar to the home page, landing pages, start loading page, home page
Of There is a lot of logic in the Viewdidappear method that launches the loading page:
-(void) Viewdidappear: (BOOL) animated{ dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_ DEFAULT, 0), ^ (void) { clientinfo = [Ylsclientinfo new]; if ([Clientinfo Needinit]) { [self mkdiranddatabasefile]; } else{ [self refreshversion:[clientinfo currentversion]; } Various processing logic });}
Then, after entering the main page, if the user exits the login, they need to go back to the homepage, so they will call the Dismissviewcontroller method on the homepage. The original code looks like this:
Uiviewcontroller *origin = self.presentingviewcontroller.presentingviewcontroller;if ([Origin isMemberOfClass:[ Ylsloginviewcontroller class]) { origin = Self.presentingViewController.presentingViewController.presentingViewController;} [Origin Dismissviewcontrolleranimated:no Completion:nil];
The expected result is. Go directly to the homepage. Then trigger the first page of the Viewdidappear method.
In fact, by observing the console warning, it was found that the Viewdidappear method of the intermediate boot loading page was also called. Landing page because there is no way to write the Viewdidappear method, so there is no discovery, but I would like to push the hypothesis that the same will be called. It seems that the viewcontroller are stacked one after the other. So each "previous" Viewcontroller Viewdidappear method should be triggered.
Check the API, and StackOverflow search for half a day. There seems to be no way to prevent this default behavior. So finally my solution is to add a tag to the controller on the middle:
-(void) Viewdidappear: (BOOL) animated{ //assumes that this method was triggered because the dismiss was called and does not initialize if (self.isdismissing) { return ; } Initialize load Logic}
Ylsbootstrapviewcontroller *bootstrapcontroller = (ylsbootstrapviewcontroller*) Self.presentingviewcontroller; bootstrapcontroller.isdismissing = YES; Uiviewcontroller *origin = self.presentingviewcontroller.presentingviewcontroller;if ([Origin isMemberOfClass:[ Ylsloginviewcontroller class]) { origin = Self.presentingViewController.presentingViewController.presentingViewController;} [Origin Dismissviewcontrolleranimated:no Completion:nil];
I don't know if we have any better practices.
A small trap for iOS calling Dismissviewcontroller