<bdo id='hpYj3'></bdo><ul id='hpYj3'></ul>

    <legend id='hpYj3'><style id='hpYj3'><dir id='hpYj3'><q id='hpYj3'></q></dir></style></legend>
    1. <small id='hpYj3'></small><noframes id='hpYj3'>

    2. <tfoot id='hpYj3'></tfoot>

      <i id='hpYj3'><tr id='hpYj3'><dt id='hpYj3'><q id='hpYj3'><span id='hpYj3'><b id='hpYj3'><form id='hpYj3'><ins id='hpYj3'></ins><ul id='hpYj3'></ul><sub id='hpYj3'></sub></form><legend id='hpYj3'></legend><bdo id='hpYj3'><pre id='hpYj3'><center id='hpYj3'></center></pre></bdo></b><th id='hpYj3'></th></span></q></dt></tr></i><div id='hpYj3'><tfoot id='hpYj3'></tfoot><dl id='hpYj3'><fieldset id='hpYj3'></fieldset></dl></div>

    3. 在 PageViewController 导航不起作用

      In PageViewController navigation not working(在 PageViewController 导航不起作用)

      <small id='rFvLD'></small><noframes id='rFvLD'>

      <i id='rFvLD'><tr id='rFvLD'><dt id='rFvLD'><q id='rFvLD'><span id='rFvLD'><b id='rFvLD'><form id='rFvLD'><ins id='rFvLD'></ins><ul id='rFvLD'></ul><sub id='rFvLD'></sub></form><legend id='rFvLD'></legend><bdo id='rFvLD'><pre id='rFvLD'><center id='rFvLD'></center></pre></bdo></b><th id='rFvLD'></th></span></q></dt></tr></i><div id='rFvLD'><tfoot id='rFvLD'></tfoot><dl id='rFvLD'><fieldset id='rFvLD'></fieldset></dl></div>
      • <bdo id='rFvLD'></bdo><ul id='rFvLD'></ul>

              <tbody id='rFvLD'></tbody>
          1. <legend id='rFvLD'><style id='rFvLD'><dir id='rFvLD'><q id='rFvLD'></q></dir></style></legend>
                <tfoot id='rFvLD'></tfoot>
              1. 本文介绍了在 PageViewController 导航不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有 3 种类型的 VC,第一种 VC,第 2 种 VC 是 PageViewController 有 3 个页面(我在这里添加了 PageController 到普通 ViewController),第三个是FinalViewController.

                I have 3 types of VC's , 1st Vc, 2nd VC is PageViewController with 3 pages(I added PageController to normal ViewController here), third one is FinalViewController.

                第一个 VC 有按钮,当我单击它时,它将移动到第二个 VC,即 PageViewController(它有 3 个页面 [3 个 ViewConrollers] 工作正常).

                1st VC has button when i click it will move to 2nd VC that is PageViewController(It has 3 pages[3 ViewConrollers] working fine).

                在加载第一个 VC 后的 PageViewController 中,当我点击我想完全导航 FinalViewController 时,它具有带有手势的 view.

                In PageViewController after loading first VC, it has view with gestures when i tap that i want to navigate FinalViewController completely.

                这里导航不起作用.

                我的第一个 VC 代码

                My 1st VC code

                     override func viewWillAppear(_ animated: Bool) {
                        self.navigationController?.navigationBar.isHidden = true
                    }
                
                    override func viewWillDisappear(_ animated: Bool) {
                        self.navigationController?.navigationBar.isHidden = false
                    }
                
                    @IBAction func btn(_ sender: Any) {
                
                        let storyboard = self.storyboard?.instantiateViewController(withIdentifier: "NVC")
                        self.navigationController?.pushViewController(storyboard!, animated: true)
                    }
                
                My PageViewController code
                
                    import UIKit
                
                    class NewViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
                
                    @IBOutlet weak var pagerController: UIPageControl!
                    @IBOutlet weak var pageControllerView: UIView!
                
                    // The pages it contains
                    var pages =  [UIViewController]()
                
                    // The UIPageViewController
                    var pageContainer: UIPageViewController!
                    // Track the current index
                    var currentIndex: Int?
                    private var pendingIndex: Int?
                
                    override func viewDidLoad() {
                        super.viewDidLoad()
                
                        // Setup the pages
                        let storyboard = UIStoryboard(name: "Main", bundle: nil)
                        let page1 = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
                        let page2: UIViewController! = storyboard.instantiateViewController(withIdentifier: "SecondViewController")
                        let page3: UIViewController! = storyboard.instantiateViewController(withIdentifier: "ThirdViewController")
                        pages.append(page1)
                        pages.append(page2)
                        pages.append(page3)
                
                        page1.variable = "This is strig..."
                
                        // Create the page container
                        pageContainer = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
                        pageContainer.delegate = self
                        pageContainer.dataSource = self
                        pageContainer.setViewControllers([page1], direction: UIPageViewController.NavigationDirection.forward, animated: false, completion: nil)
                
                        // Add it to the view
                        pageControllerView.addSubview(pageContainer.view)
                
                        // Configure our custom pageControl
                        view.bringSubviewToFront(pagerController)
                        pagerController.numberOfPages = pages.count
                        pagerController.currentPage = 0
                
                
                    }
                
                    override func didReceiveMemoryWarning() {
                        super.didReceiveMemoryWarning()
                        // Dispose of any resources that can be recreated.
                    }
                
                
                    // MARK: - UIPageViewController delegates
                
                    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
                        let currentIndex = pages.firstIndex(of:viewController)!
                        if currentIndex == 0 {
                            return nil
                        }
                        let previousIndex = abs((currentIndex - 1) % pages.count)
                        return pages[previousIndex]
                    }
                
                    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
                        let currentIndex = pages.firstIndex(of:viewController)!
                        if currentIndex == pages.count-1 {
                            return nil
                        }
                        let nextIndex = abs((currentIndex + 1) % pages.count)
                        return pages[nextIndex]
                    }
                
                
                    func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
                        pendingIndex = pages.firstIndex(of:pendingViewControllers.first!)
                    }
                
                    func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
                        if completed {
                            currentIndex = pendingIndex
                            if let index = currentIndex {
                                pagerController.currentPage = index
                            }
                        }
                    }
                
                    }
                
                My `ViewConroller` code means which is loading in `PageViewController` 
                
                    import UIKit
                
                    class ViewController: UIViewController {
                
                    var variable = String()
                    @IBOutlet weak var subView: UIView!
                
                    override func viewDidLoad() {
                        super.viewDidLoad()
                        // Do any additional setup after loading the view.
                
                        //Add gesture to incoming call view
                        let incomingCallsViewTap = UITapGestureRecognizer(target: self, action: #selector(incomingCallsViewTapFunction(_:)))
                        self.subView!.addGestureRecognizer(incomingCallsViewTap)
                
                
                    }
                
                    // Tap gestrure selector fuction
                    @objc func incomingCallsViewTapFunction(_ sender: UITapGestureRecognizer) {
                        let clvc = self.storyboard?.instantiateViewController(withIdentifier: "FVC") as! FinalViewController
                        self.navigationController?.pushViewController(clvc, animated: false)
                    }
                
                
                
                    @IBAction func btn(_ sender: Any) {
                
                        print("ViewController one")
                
                        print(variable)
                    }
                
                    }
                
                

                推荐答案

                navigationViewController 为 nil,所以我必须执行以下操作:

                navigationViewController is nil so I had to do the following:

                (UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.pushViewController(clvc, animated: true)
                
                
                // Tap gestrure selector fuction
                @objc func incomingCallsViewTapFunction(_ sender: UITapGestureRecognizer) {
                    let clvc = self.storyboard?.instantiateViewController(withIdentifier: "FVC") as! FinalViewController
                //        self.navigationController?.pushViewController(clvc, animated: false)
                
                    (UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.pushViewController(clvc, animated: true)
                
                }
                

                这篇关于在 PageViewController 导航不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                ViewController in UINavigationController orientation change(UINavigationController 中的 ViewController 方向更改)
                How to add a navigation controller programmatically in code but not as initial view controller(如何在代码中以编程方式添加导航控制器,但不作为初始视图控制器)
                The correct way to set a light status bar text color in iOS 7 based on different ViewControllers(iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法)
                View being blocked by UITransitionView after being presented(呈现后被 UITransitionView 阻止的视图)
                presentViewController not supporting orientation in iOS 6(presentViewController 在 iOS 6 中不支持方向)
                Navigate Back to previous view controller(导航回上一个视图控制器)
                  <bdo id='HbJse'></bdo><ul id='HbJse'></ul>
                • <tfoot id='HbJse'></tfoot>

                  • <legend id='HbJse'><style id='HbJse'><dir id='HbJse'><q id='HbJse'></q></dir></style></legend>
                      <tbody id='HbJse'></tbody>

                  • <small id='HbJse'></small><noframes id='HbJse'>

                          <i id='HbJse'><tr id='HbJse'><dt id='HbJse'><q id='HbJse'><span id='HbJse'><b id='HbJse'><form id='HbJse'><ins id='HbJse'></ins><ul id='HbJse'></ul><sub id='HbJse'></sub></form><legend id='HbJse'></legend><bdo id='HbJse'><pre id='HbJse'><center id='HbJse'></center></pre></bdo></b><th id='HbJse'></th></span></q></dt></tr></i><div id='HbJse'><tfoot id='HbJse'></tfoot><dl id='HbJse'><fieldset id='HbJse'></fieldset></dl></div>