gpt4 book ai didi

ios - 使用第二个 UIViewController 启动 ViewPagerController

转载 作者:行者123 更新时间:2023-11-28 15:43:20 28 4
gpt4 key购买 nike

我有一个 viewpagercontroller 并让它与 3 个预先设置的 UIViewController 一起正确运行,但是当我加载应用程序时它首先显示第一个 UIViewController,我想先显示第二个 UIViewController,但是我在实现这个时遇到了麻烦.

这是我的 ViewDidLoad()

override func viewDidLoad() {
super.viewDidLoad()

self.dataSource = self
if let firstViewController = orderedViewControllers.first {
setViewControllers([firstViewController],
direction: .forward,
animated: true,
completion: nil)
}

}

这是我的 orderedViewControllers

private(set) lazy var orderedViewControllers: [UIViewController] = {
return [self.newProfileViewController(vc: "UserContentViewController"),
self.newProfileViewController(vc: "ProfileViewController"),
self.newProfileViewController(vc: "NotificationViewController")]
}()

最佳答案

你可以用你想要的索引来实现这个功能,

func scrollToViewController(index newIndex: Int) {
if let firstViewController = viewControllers?.first,
let currentIndex = orderedViewControllers.indexOf(firstViewController) {
let direction: UIPageViewControllerNavigationDirection = newIndex >= currentIndex ? .Forward : .Reverse
let nextViewController = orderedViewControllers[newIndex]
scrollToViewController(nextViewController, direction: direction)
}
}

关于ios - 使用第二个 UIViewController 启动 ViewPagerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43435614/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com