[英]Set storyboard ID programmatically for custom UIViewController?
我创建了一个新类,它是一个自定义UIViewController
。
我将使用两个自定义UIViewController
和一个UIPageViewController
以便可以在它们之间左右滑动。
由于以编程方式为每个自定义UIViewController
设置Storyboard ID
的性质,使该方法无法正常工作
正如您在下面的代码中看到的那样,由于遇到以下错误,因此我永远不会越过用注释标记的点: Storyboard (<UIStoryboard: 0x7f9f404174c0>) doesn't contain a view controller with identifier 'id_AssetViewer_A'
注意:我需要以编程方式设置Storyboard ID
, 而不是通过编辑器!
我的代码:
UIPageViewController *pageController = [self.storyboard instantiateViewControllerWithIdentifier: @"BrowserPageController"];
pageController.dataSource = self;
[[pageController view] setFrame:[[self view] bounds]];
assetViewer_A = [[AssetViewer alloc] init];
assetViewer_A = [self.storyboard instantiateViewControllerWithIdentifier: @"id_AssetViewer_A"]; //<< error occurs here!
assetViewer_A.view.tag = 0;
assetViewer_B = [[AssetViewer alloc] init];
assetViewer_B = [self.storyboard instantiateViewControllerWithIdentifier: @"id_AssetViewer_B"];
assetViewer_B.view.tag = 0;
NSArray *startingViewControllers = [NSArray arrayWithObject: assetViewer_A];
[pageController setViewControllers: startingViewControllers
direction: UIPageViewControllerNavigationDirectionForward
animated: NO
completion: nil];
self.browserViewController = pageController;
[self addChildViewController: self.browserViewController];
[self.view addSubview: self.browserViewController.view];
[self.browserViewController didMoveToParentViewController: self];
if ([pageController.view.subviews.firstObject isKindOfClass:[UIScrollView class]]) {
browserPageView_as_ScrollView = (UIScrollView *)pageController.view.subviews.firstObject;
browserPageView_as_ScrollView.delegate = self;
}
PS: Storyboard ID
需要通过代码定义 ,而不是在可视编辑器中手动定义 。
在情节提要中一次定义资产视图控制器,并为其指定一个情节提要ID“ id_assetViewer”。
然后,在实例化资产查看器的两个位置(A和B)中的代码中都使用此ID。
无需使用其他故事板ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.