How can I use an Embed Segue in iOS 5?

前端 未结 2 1131
孤独总比滥情好
孤独总比滥情好 2021-02-09 23:26

iOS 6 introduced the Embed Segue, allowing custom container controllers to be used in Storyboards. Is there anyway to duplicate this for iOS 5?

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-09 23:48

    I duplicated the functionality by subclassing UIStoryboardSegue.

    In Interface Builder, I create a custom segue and set its' class to my subclass (QCEmbedSegue). In my parent view controller's viewDidLoad, I call performSegueWithIdentifier:sender.

    QCEmbedSegue simply overrides perform:

    - (void)perform
    {
        [self.sourceViewController addChildViewController:self.destinationViewController];
        [[self.sourceViewController view] addSubview:[self.destinationViewController view]];
        [self.destinationViewController didMoveToParentViewController:self.sourceViewController];
    }
    

    http://www.quentamia.com/blog/embed-segue-in-ios-5/

提交回复
热议问题