gpt4 book ai didi

ios - 如何以编程方式从 Storyboard 中的 View Controller 加载弹出窗口。

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:12:57 28 4
gpt4 key购买 nike

当用户点击按钮时,我正在从 Collection View 单元格中加载弹出窗口。我已经设法让弹出窗口工作,但我不知道如何加载我在 Storyboard 中设置的 View Controller 。

这是获取弹出窗口的代码。我怎样才能让它从 Storyboard 中加载 View Controller ?

self.popoverContent = [[PopOverViewController alloc]initWithNibName:@"UpcomingCells" bundle:nil];


UIView *popoverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];


[popoverView setBackgroundColor:[UIColor colorWithRed:224/256.0 green:45/256.0 blue:117/256.0 alpha:1.0]];



self.popoverContent.view = popoverView;

self.popoverContent.contentSizeForViewInPopover = CGSizeMake(200, 300);

self.contactPopover =[[UIPopoverController alloc] initWithContentViewController:self.popoverContent];

[self.contactPopover presentPopoverFromRect:self.remindButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES ];

[self.contactPopover setDelegate:self];

最佳答案

文档对此很清楚,你应该使用

-instantiateViewControllerWithIdentifier:;

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIStoryboard_Class/Reference/Reference.html

因此假设您需要将 viewController 加载到 self.popOverContent 中,您可以这样做

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"nameOfStoryboard" 
bundle:nil];
self.popoverContent = [storyBoard instantiateViewControllerWithIdentifier:@"nameOfViewController"];

只需用实际名称替换 nameOfViewController 和 nameOfStoryboard ;)

编辑: Storyboard名称只是您的 Storyboard文件的名称,减去扩展名。所以对于“myStoryboard.storyboard”,你只需使用“myStoryboard”。您还需要为您的 viewController 设置一个 stoyboard-Identifier。它被称为 stryboard-id,它就位于您在身份检查器中为 viewController 设置类名的位置下方。

关于ios - 如何以编程方式从 Storyboard 中的 View Controller 加载弹出窗口。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17522089/

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