代码之家  ›  专栏  ›  技术社区  ›  SashaZ

使用presentViewController转到BWWalkthroughViewController中的特定视图

  •  1
  • SashaZ  · 技术社区  · 9 年前

    我正在使用BBWalkthrough( https://github.com/ariok/BWWalkthrough )我想直接从 presentViewController 过渡

    我该怎么做?注意,我没有使用segues,因为viewController位于不同的故事板中。

    如果我做了 presentViewController() 到BBWalkthroughViewController实例的子VC walk 那么它显示得很好,但你不能从该视图中滚动(即,你在视图中,但没有滚动功能,因为它与其他视图没有任何链接)。

    func instantiateControllers(){
    // Get view controllers and build the walkthrough
    let stb = UIStoryboard(name: "Walkthrough", bundle: nil)
    let walkthrough = stb.instantiateViewControllerWithIdentifier("walk") as! BWWalkthroughViewController
    let page_A = stb.instantiateViewControllerWithIdentifier("walkA") as! UIViewController
    let page_B = stb.instantiateViewControllerWithIdentifier("walkB") as! UIViewController
    let page_C = stb.instantiateViewControllerWithIdentifier("walkC")as! UIViewController
    let page_D = stb.instantiateViewControllerWithIdentifier("walkD")as! UIViewController
    let page_E = stb.instantiateViewControllerWithIdentifier("walkE")as! UIViewController
    let page_outro = stb.instantiateViewControllerWithIdentifier("walkOUT")as! UIViewController
    
    // Attach the pages to the master
    walkthrough.delegate = self
    walkthrough.addViewController(page_A)
    walkthrough.addViewController(page_B)
    walkthrough.addViewController(page_C)
    walkthrough.addViewController(page_D)
    walkthrough.addViewController(page_E)
    walkthrough.addViewController(page_outro) 
    self.presentViewController(walkthrough, animated: true, completion: nil)
    }
    
    1 回复  |  直到 9 年前
        1
  •  3
  •   BaseZen    9 年前

    我会打电话给 @IBAction func nextPage() 方法 walkthrough 期望的次数。它相当于用动画模拟用户页面的点击,这不是bug就是特性。

    要么就是这样,要么就是破解代码的源代码——这就是开源的要点。:-)只要做 gotoPage() 函数非私有,并从上面的代码中调用一次。没有充分的理由认为该设计将该功能设为私有。

    在任何一种情况下,我认为您都必须作为完成处理程序的一部分这样做。

    示例:

    // Assuming you've removed 'private' from the gotoPage() function
    self.presentViewController(walkthrough, animated: true) {  walkthrough.gotoPage(3) }
    

    或:

    self.presentViewController(walkthrough, animated: true) {
        for _ in 0..<3 {
            walkthrough.nextPage()
        }
    }