ios - 如何显示没有数据的 UIPageViewController?

标签 ios uipageviewcontroller

我使用 UIPageViewController 作为浏览照片库中照片的一种方式。当照片存在时它可以工作,但如果手机上不存在照片,它会崩溃。错误:

2015-04-19 16:27:05.305 MyApp[2566:1278254] *** Assertion failure in -[MyPageViewController queuingScrollView:didBailoutOfScrollAndRevealedView:], /SourceCache/UIKit/UIKit-3347.44/UIPageViewController.m:1903
2015-04-19 16:27:05.308 MyApp[2566:1278254] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view (null)'

当不存在照片时,数据源委托(delegate)方法确实返回 nil,所以我原以为页面 View Controller 不会显示任何内容。显然,这是不正确的。

当当前没有数据显示在 UIPageViewController 中时,处理这种情况的正确方法是什么?制作一个虚拟页面内容 View Controller 并将其交给页面 View Controller ,以便它有一些要显示的内容?

最佳答案

@matt 是正确的:问题是没有设置初始页面 Controller ,这导致了崩溃。创建一个虚拟 View Controller 就可以了:
[self.storyboard instantiateViewControllerWithIdentifier:@"NoPhotosViewController"];

关于ios - 如何显示没有数据的 UIPageViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29737319/

相关文章:

ios - 为什么身份验证不适用于我的 ASP.NET REST API?

iphone - Ad-Hoc 分发提示消息显示 (null) 想要安装 {app name}

ios - Metal 数组索引使用文字工作但使用变量崩溃

swift - 添加为 subview 时 UIPageViewController 无法识别滑动

ios - 一个模型应该做多少设置?

ios - 如何测试静默通知在 iOS 中是否正常工作?

ios6 - UIPageViewController 使用滚动过渡样式导航到错误的页面

ios - 在 Swift 3 中从 UIPageViewController 中删除黑边

ios - 如何修复 UIPageViewController 页面中突出显示状态的 UIButton 延迟?

ios - Monotouch 绑定(bind)无法接受委托(delegate)模型