Summary of common errors and warnings in development (21) Solution for Warning:attempt to present on whose view are not in the window hierarchy!
When I want to jump from one VC to another VC, the general will use
-(Void) Presentviewcontroller: (Uiviewcontroller *) viewcontrollertopresent animated: ( BOOL) Flag Completion: (Void (^) (void)) completion; Of course, you can also use navigation push.
But yesterday met the topic of warning, in StackOverflow found the answer: Click to open the link
The main idea is that page jumps must be done after Viewdidload and viewdidappear. The solution is to make sure that the page jumps after view load is complete. The great God said that can be achieved by setting the delay, through the experiment I think this bad control, in the end need to delay how much?
Later, a plan was changed to use the Viewdidload
1 [selfperformselectoronmainthread: @selector (login) WithObject:nilwaitUntilDone:NO];
Write the page jump code into the function, and then set the Waituntildone to No, that is, viewdidload directly returned without login execution. This makes sure that the page jumps in login are executed after viewdidload.
In addition, I also encountered the following situation: A page jumps to B, in B is also encapsulated a page jump (to C).
That is, in the previous login function, a jump from A to B will be passed tokens, secret and so on to obtain user authorization data, and then in B to adjust the large companies in the packaging of the authorization page (such as Baidu Network disk, Sina Weibo).
At first my login implementation is as follows:
1 2 3 *loginvc=[[Loginviewcontrolleralloc] init]; 4 5 delegate= self; 6 7 self presentviewcontroller:loginvc animated:NOcompletion:nil]; 8 9 auth:baidu_api_key secret:nil Disk:baidu]; There's a jump to the authorization page in this function.
This also causes the problem, and the solution is to put the last line of functions in the completion block.
1 2 3 *loginvc=[[Loginviewcontroller alloc] init]; 4 5 delegate= self; 6 7 Self presentviewcontroller:loginvc animated:no completion:^{[LOGINVC Auth:baidu_api_key Secret:nil Disk:baidu];}]; 8 9 }
Because:
- The completion handler, if provided, 'll be a invoked after the presented controllers Viewdidappear:callback is invoked.
iOS Development--Error summary & common errors and warnings in development summary (21)