IOS: Using segue in popover

Source: Internet
Author: User

This is a problem that occurs for a long time tonight. If you use segue, the normal execution order is: first execute the prepareforsegue of the source viewcontroller, and then execute the viewdidload of the target VC, therefore, you can set the attributes of the destination Vc in prepareforsegue to transfer the value. However, when you use the segue in the popover scenario, the situation is different. The system first calls the viewdidload for the purpose and then calls the prepareforsegue of the source vc. It is reversed, therefore, the method of passing values by value just mentioned won't work (especially when you need to use this attribute for some logic in the target viewdidload ).

Solution: Method 1: discard the segue and directlyCodeAdd A popover.

Destinationvc =[StoryboardInstantiateviewcontrollerwithidentifier:@ "Destinationvc"];

Destinationvc. Mmm = @ "Hello Zhan! ";

Popover =[[Uipopovercontrolleralloc]Initwithcontentviewcontroller: Destinationvc]; // The viewdidload

.......

Method 2: Put the logic of viewdidload in a function and change the logic in the prepareforsegue of the source vc. This stackoverflow also mentions http://stackoverflow.com/questions/8838160/prepareforsegue-is-not-called-after-performseguewithidentifier-with-popover-st

 

Related Article

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.