ios - Storyboard中的 UIPopoverPresentationController

标签 ios objective-c uistoryboard

我正在从代码初始化我的 UIPopoverPresentationController:

ChoseOptionsViewController *contentController = [[ChoseOptionsViewController alloc] init];
contentController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *copvc = contentController.popoverPresentationController;
copvc.permittedArrowDirections = UIPopoverArrowDirectionAny;
copvc.sourceView = sender;
copvc.sourceRect = sender.bounds;
contentController.preferredContentSize = CGSizeMake(200, 200);
[self presentViewController:contentController animated:YES completion:nil];

我得到的只是一个空的 200x200 View ,尽管我已经在 Storyboard中创建了一个 ViewController,为其分配了 ChoseOptionsViewController 类并拖动了一些 UI 元素。 请告诉我,在从代码初始化弹出窗口时,如何从 Storyboard 中获取我的 View 。 提前致谢。

最佳答案

当你在 Storyboard中创建一个 View Controller 时,你应该使用 instantiateViewControllerWithIdentifier: 创建它的一个实例,而不是 alloc init。

ChoseOptionsViewController *contentController = [self.storyboard instantiateViewControllerWithIdentifier:@"Whatever"];

确保 Storyboard 中的 Controller 将其标识符设置为您传递给方法的相同字符串。

关于ios - Storyboard中的 UIPopoverPresentationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26453247/

相关文章:

IOS/objective-C : Access to variables within switch statements

objective-c - RestKit 0.20 — 核心数据 : error: Failed to call designated initializer on NSManagedObject class

iphone - 如何设置 iPod 音量而不影响其他音量?

ios - 如何重定向到一个页面

IOS 基于页面的应用程序 : How to jump to another page

ios - 解压内容 应用内购买 ios

ios - APNS通知下发失败(错误码8)

iphone - 使用 DidSelectRow 选择作为键/过滤器对象来过滤 NSDictionary

objective-c - 有没有办法做一半的换行符?

ios - 在 IOS 中调用另一个屏幕时出现异常