OGeek|极客世界-中国程序员成长平台

标题: ios - XIB 错误中的 UIPageViewController [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:40
标题: ios - XIB 错误中的 UIPageViewController

我有一个子类 View Controller ,在 Interface Builder 中,我希望 VC View 的 subview 成为 UIPageViewController 的 View 。我将 UIPageViewController 的数据源设置为文件的所有者,并将 View 属性设置为我的 VC 的 subview 。这个功能可以实现吗?或者我不能以这种方式使用 UIPageVC?大多数示例是针对 Storyboard的,而不是由 NavigationController 方式推送的旧 VC。我得到这个异常'[UIView invalidatePageViewController]'。



Best Answer-推荐答案


当我有一个 UIViewController 作为我的 Root View 时,我也遇到了同样的事情 - 我的 UIViewController 有一个属性定义为:

@property (strong, nonatomic) IBOutlet UIPageViewController *pageViewController;

我的 IBoutlet 也连接到我的 xib 中的 UIPageViewController。

解决方案:移除 IBoutlet 并断开 UIPageViewController 与我的 xib 的连接

@property (strong, nonatomic) UIPageViewController *pageViewController;

也许崩溃与“每个 View 应该只有一个 View Controller ”有关

另外,如果你这样做,在“viewdidload”中 _pageViewController.view = _apageView;

_apageView 在你的 UIViewController 中的位置:

@property (strong, nonatomic) IBOutlet UIView *apageView;

这也会导致同样的崩溃发生 - 因此您需要这样做:

[_apageView addSubview:_pageController.view];

那么崩溃不应该发生。

关于ios - XIB 错误中的 UIPageViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15462491/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4