Our app starts from the start to the main page, is constructed by Presentviewcontroller a viewcontroller sequence, similar to the home page, landing pages, start loading page, home page
Among them, the Viewdidappear method that starts the loading page does a lot of logic processing:
-(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 landing, 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 to go directly to the homepage and then trigger the Viewdidappear method on the homepage. 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 write Viewdidappear method, so there is no discovery, but I guess if there is, the same will be called. It seems that Viewcontroller is sequentially 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 was to add a tag to the controller on the middle:
-(void) Viewdidappear: (BOOL) animated{ //If this method is triggered by a call to dismiss, do 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