iosstoryboardxcode4.6uipopover

How do I get a Storyboard-created UIViewController without using seagues into a UIPopover?


I have an iPad app (XCode 4.6, iOS 6.2, Storyboards, ARC) where I created a UIViewController (not connected to any segue) to be used in a UIPopover. These are the ViewController settings:

enter image description here

enter image description here

I have this code that is supposed to display the "viewForPopover" ViewController from within a UIPopover.

        UIView *anchor = textField;
    UIViewController *viewControllerForPopover =
    [self.storyboard instantiateViewControllerWithIdentifier:@"viewForPopover"];

    popover = [[UIPopoverController alloc]
               initWithContentViewController:viewControllerForPopover];
    [popover presentPopoverFromRect:anchor.frame
                             inView:anchor.superview
           permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

My problem is: there is no self.storyboard. So how am I supposed to get to the view controller which lies outside of the current class? (current class is a subview of UIView)


Solution

  • Call this method on UIStoryboard:

    + (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil

    probably like this if your view controller live in 'MainStoryboard.storyboard':

    UIViewController *viewControllerForPopover = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]instantiateViewControllerWithIdentifier:@"viewForPopover"];