gpt4 book ai didi

ios - 以编程方式为自定义UIViewController设置 Storyboard ID?

转载 作者:行者123 更新时间:2023-12-02 11:02:34 26 4
gpt4 key购买 nike

我创建了一个新类,它是一个自定义UIViewController

我将使用带有UIViewController的两个自定义UIPageViewController,以便可以在它们之间左右滑动。

由于以编程方式设置每个自定义Storyboard IDUIViewController的性质,我无法使它正常工作

正如您在下面的代码中看到的那样,由于遇到以下错误,所以我永远不会超过用注释标记的点: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必须由代码定义为 ,而不是在可视编辑器中手动定义。

最佳答案

在 Storyboard 中一次定义 Assets View Controller ,并为其指定一个 Storyboard ID“id_assetViewer”。

然后,在实例化 Assets 查看器的两个位置(A和B)中的代码中都使用此ID。

无需使用其他 StoryboardID。

关于ios - 以编程方式为自定义UIViewController设置 Storyboard ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33060981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com