我有一个iPad应用程序(XCode 4.6,iOS 6.2,情节提要,ARC),我在其中创建了一个UIViewController(未连接到任何segue)以用于UIPopover。这些是ViewController设置:
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9MYjZQZC5wbmcifQ==” alt =“在此处输入图像描述”>
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9iZ0N4ci5wbmcifQ==” alt =“在此处输入图像描述”>
我有应该在UIPopover中显示“ viewForPopover” ViewController的代码。
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];
我的问题是:没有self.storyboard。那么我应该如何到达当前类之外的视图控制器呢? (当前类是UIView的子视图)
在UIStoryboard上调用此方法:
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil
如果您的视图控制器位于“ MainStoryboard.storyboard”中,则可能像这样:
UIViewController *viewControllerForPopover =
[[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]instantiateViewControllerWithIdentifier:@"viewForPopover"];
快速实用功能:
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)
}
}
}
其中MyController.swift为类的swift文件,而MyController.xib是包含UI的文件。