Reputation: 4984
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:
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)
Upvotes: 3
Views: 6407
Reputation: 11666
utility function for swift:
extension UIViewController {
func presentMyCtl( pushed: Bool){
let VC = MyController(nibName: "MyController", bundle: nil)
if pushed{
let nc = self.navigationController!
nc.pushViewController(VC, animated: true)
}else{
self.present(VC, animated: true, completion: nil)
}
}
func dismissMyCtl(pushed: Bool){
if pushed{
let nc = self.navigationController!
nc.popViewController(animated: true)
}else{
self.dismiss(animated: true, completion: nil)
}
}
}
where MyController.swift if the swift file for class, and MyController.xib is the file containing the UI.
Upvotes: 0
Reputation: 10195
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"];
Upvotes: 8