我有一个iPad应用程序(XCode 4.6,iOS 6.2,Storyboards,ARC),我在其中创建了一个UIViewController(未连接到任何segue)以在UIPopover中使用。这些是ViewController设置:
我有这个代码可以在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的子视图)
答案 0 :(得分:8)
在UIStoryboard上调用此方法:
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil
可能是这样的:
UIViewController *viewControllerForPopover =
[[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]instantiateViewControllerWithIdentifier:@"viewForPopover"];
答案 1 :(得分:0)
快速实用工具
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的文件。