gpt4 book ai didi

swift - nstimer 无法正常工作,显示相同的数据,并且页面 Controller 也不指示页面

转载 作者:行者123 更新时间:2023-11-30 12:42:17 25 4
gpt4 key购买 nike

我想实现页面 Controller 并为页面 Controller 设置计时器

这里我使用了传递标签的对象的标签数组

但是在这里我获得了相同的值,页面 Controller 也没有移动,当在标签中显示相同的数据时,请帮助我解决这个问题......提前致谢。这是我的代码:

override func viewDidLoad() 
{
super.viewDidLoad()
arrPageTitle = ["In SignUp screen user can able to input the first name, last name, emailid and password.", "After SignUp email verification link has been send to his mail then add basic profile information and sport preferences.", "In Profile setting can view profile, privacy and notifications, friends, account and championships won."];
self.pageViewController = self.storyboard?.instantiateViewController(withIdentifier: "myPageviewcontroller") as! UIPageViewController
self.pageViewController.dataSource = self
let initialContentviewcontroller = self.getViewControllerAtIndex(index: 0) as PageContentViewController
let viewcontrollers = NSArray(object: initialContentviewcontroller)
self.pageViewController.setViewControllers(viewcontrollers as? [UIViewController], direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
self.pageViewController.view.frame = CGRect(x: 0, y: 50, width:self.view.frame.width,height: 350)
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMove(toParentViewController: self)
timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: (#selector(StartUpPage.advancePage)), userInfo: nil, repeats: true)
}

func advancePage ()
{
let pvcs = pageViewController.childViewControllers as! [PageContentViewController]
let itemIndex = pvcs[0].pageIndex
let firstController = getViewControllerAtIndex(index: itemIndex+1)
let startingViewControllers = [firstController]
pageViewController.setViewControllers(startingViewControllers, direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
}

func getViewControllerAtIndex(index: Int) -> PageContentViewController
{ // Create a new view controller and pass suitable data.
let pageContentViewController = self.storyboard?.instantiateViewController(withIdentifier: "PageContentViewController") as! PageContentViewController
pageContentViewController.strTitle = "\(arrPageTitle[index])"
pageContentViewController.pageIndex = index
return pageContentViewController
}


func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?
{
let viewController = viewController as! PageContentViewController
var index = viewController.pageIndex as Int
if(index == 0 || index == NSNotFound) {
return nil
}
index -= 1
return self.getViewControllerAtIndex(index: index)
}

public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?
{
let viewController = viewController as! PageContentViewController
var index = viewController.pageIndex as Int
if((index == NSNotFound)) {
return nil
}
index += 1
if(index == arrPageTitle.count) {
return nil
}
return self.getViewControllerAtIndex(index: index)
}

public func presentationCount(for pageViewController: UIPageViewController) -> Int
{
return arrPageTitle.count
}
public func presentationIndex(for pageViewController: UIPageViewController) -> Int
{
return 0
}

最佳答案

func advancePage ()
{
UpdateCounter += 1

if UpdateCounter > 2 {
UpdateCounter = 0

}
var nextviewcontroller = self.getViewControllerAtIndex(index: UpdateCounter)
if (nextviewcontroller .isEqual(nil)) {
UpdateCounter = 0

nextviewcontroller = self.getViewControllerAtIndex(index: UpdateCounter)
}

let startingViewControllers = [nextviewcontroller]
pageViewController.setViewControllers(startingViewControllers, direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
pagecontroller.currentPage = UpdateCounter
pagecontroller.pageIndicatorTintColor = UIColor.lightGray
pagecontroller.currentPageIndicatorTintColor = UIColor.red

print(UpdateCounter)



}

尝试使用此代码希望能起作用

关于swift - nstimer 无法正常工作,显示相同的数据,并且页面 Controller 也不指示页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42089741/

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