我正在从代码初始化我的 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/