Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 586
SpokaneDude Avatar asked Nov 30 '25 23:11

SpokaneDude


1 Answers

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"];

like image 90
Mike Pollard Avatar answered Dec 02 '25 14:12

Mike Pollard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!