我一直在尝试为App构建一个简单的轮播滚动器。我的代码似乎没有任何错误,但是当我运行模拟器时,它崩溃并停留在黑屏上。
我试图通过使用调试器并设置一些断点来隔离问题,但是不断弹出的消息是相同的。由于该问题似乎是一个折旧的函数,因此我尝试浏览Xcode文档,以查看是否正在使用不再受支持的任何函数。我注意到其中之一,因此我着手修复代码。但是,当我再次运行该程序后,仍然显示相同的消息。
import UIKit
class PageControlViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
lazy var orderedViewControllers: [UIViewController] = {
return [self.newVC(viewController:"FirstScreen"), self.newVC(viewController:"SecondScreen"),
self.newVC(viewController:"ThirdScreen")
]
}()
var pageControl = UIPageControl()
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
self.delegate = self
if let firstViewController = orderedViewControllers.first{
setViewControllers([firstViewController], direction: .forward, animated: true, completion: nil)
}
configurePageControl()
}
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
let pageContentViewController = pageViewController.viewControllers![0]
self.pageControl.currentPage = orderedViewControllers.firstIndex(of: pageContentViewController)!
}
func configurePageControl() {
pageControl = UIPageControl(frame: CGRect(x:0, y:UIScreen.main.bounds.maxY - 50, width: UIScreen.main.bounds.width, height: 50))
pageControl.numberOfPages = orderedViewControllers.count
pageControl.currentPage = 0
pageControl.tintColor = .black
pageControl.pageIndicatorTintColor = .white
pageControl.currentPageIndicatorTintColor = .black
self.view.addSubview(pageControl)
}
func newVC(viewController: String)->UIViewController {
return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: viewController)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.firstIndex(of: viewController) else {
return nil
}
let previousIndex = viewControllerIndex - 1
guard previousIndex >= 0 else{
return nil
}
guard orderedViewControllers.count > previousIndex else {
return nil
}
return orderedViewControllers[previousIndex]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.firstIndex(of: viewController) else {
return nil
}
let nextIndex = viewControllerIndex + 1
guard orderedViewControllers.count > nextIndex else {
return nil
}
guard orderedViewControllers.count > nextIndex else {
return nil
}
return orderedViewControllers[nextIndex]
}
}
这些是我的错误消息:
2019-07-15 21:07:20.479200-0700 AccountabiliBuddies [64597:16812545] [常规] CFLocaleCopyCurrent()无法通过查找当前语言环境 用户首选项中的“ AppleLocale”和“ AppleLanguages”;后退 默认为区域设置标识符“ en_US”。考虑检查控制台 对于此流程中违反沙箱的行为,以便从偏好设置中进行读取, 或启用CoreFoundation调试日志记录以获取更多信息。这个 只会记录一次。
2019-07-15 21:07:20.555741-0700 AccountabiliBuddies [64597:16811883] [声明] UIKIT客户端中的兼容性错误:移动方法 从UICanvas到UIWindowScene的canvasToolbar
2019-07-15 21:07:20.556155-0700 AccountabiliBuddies [64597:16811883] [声明]注册画布组件类 _UICanvasUserActivityManager,请更新到框架组件
2019-07-15 21:07:20.561116-0700 AccountabiliBuddies [64597:16811883] [声明]在UICanvas上调用不推荐使用的SPI。这个方法和类 将在通用汽车之前消失
2019-07-15 21:07:20.562484-0700 AccountabiliBuddies [64597:16811883] [Storyboard]接口中的未知类PageControlViewController 生成器文件。
2019-07-15 21:07:20.564595-0700 AccountabiliBuddies [64597:16811883] [TraitCollection] _UISheetPresentationController类将覆盖 -traitCollection getter,不支持。如果要覆盖特征,则必须使用适当的API。
2019-07-15 21:07:20.564714-0700 AccountabiliBuddies [64597:16811883] [TraitCollection] _UIRootPresentationController类会覆盖 -traitCollection getter,不支持。如果要覆盖特征,则必须使用适当的API。
2019-07-15 21:07:20.591508-0700 AccountabiliBuddies [64597:16811883] [TraitCollection]类UIPopoverPresentationController覆盖了 -traitCollection getter,不支持。如果要覆盖特征,则必须使用适当的API。
2019-07-15 21:07:20.598233-0700 AccountabiliBuddies [64597:16811883] [声明]在UICanvas上调用不推荐使用的SPI。这个方法和类 将在通用汽车之前消失