iOS Development--Error summary & common errors and warnings in development summary (21)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.