Git Product home page Git Product logo

Comments (4)

rechsteiner avatar rechsteiner commented on August 15, 2024

Yes, you need to load each view controller using instantiateViewController: on the storyboard and then manually setup a PagingViewController. Here's an example:

override func viewDidLoad() {
    super.viewDidLoad()
    
    // Load each of the view controllers you want to embed
    // from the storyboard.
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let firstViewController = storyboard.instantiateViewController(withIdentifier: "FirstViewController")
    let secondViewController = storyboard.instantiateViewController(withIdentifier: "SecondViewController")
    
    // Initialize a FixedPagingViewController and pass
    // in the view controllers.
    let pagingViewController = FixedPagingViewController(viewControllers: [
      firstViewController,
      secondViewController
    ])
    
    // Make sure you add the PagingViewController as a child view
    // controller and contrain it to the edges of the view.
    addChildViewController(pagingViewController)
    view.addSubview(pagingViewController.view)
    view.constrainToEdges(pagingViewController.view)
    pagingViewController.didMove(toParentViewController: self)

  }

I will look into other ways of setting up a PagingViewController directly in the storyboard in the future. I've added a StoryboardExample to the project that you can check out if you want to see how the setup looks like in the storyboard.

from parchment.

kmyn avatar kmyn commented on August 15, 2024

@rechsteiner thanks for the quick response and the example.

I tried the above code (StoryboardExample) it works fine as is. So, I tried extending it a bit by adding a class (swift file) to one of the controllers (FirstViewController) as below:

>>>>>

import UIKit

class FirstViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    print("In first VC")
    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}
<<<<<

I expected the message "In first VC" (from viewDidLoad()) to get printed to the console when the app is fired but, that does not seem to happen. Am I doing something wrong? or is this what you were referring to as future work?

from parchment.

rechsteiner avatar rechsteiner commented on August 15, 2024

Yeah, you need to set class type for that view controller. You can just select the view controller in the storyboard and then set the Custom Class property to be FirstViewController like this:

screen shot 2017-02-19 at 21 14 53

from parchment.

kmyn avatar kmyn commented on August 15, 2024

I did set the class. The issue seems to be with the compiler. It worked perfectly after I ran it after a clean build. Thanks again for the quick response and the example.

from parchment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.