Comments (4)
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.
@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.
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:
from parchment.
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)
- outdated code error in PagingSizeCache HOT 3
- Getting Fatal error while using storyboard more than 2 . Unable to reload 3rd storyboard table view HOT 1
- please support indicator fixed width HOT 2
- Position of tableview is reset after tab change in header above menu example HOT 1
- Using UIAlertController in per Item HOT 3
- Navigation bar disappear when presented in a sheet. HOT 3
- About swiftUI PageView content scrollview automatically slides to the top HOT 2
- Menu item error when Archive HOT 3
- Privacy Manifest HOT 2
- Propagate .options changes when SwiftUI View is updated HOT 3
- How to fix pre-loading? I want to disable it HOT 3
- Regarding the problem that PageContentView will be reloaded when you slide it left or right. HOT 3
- Incorrect index when tab menu or swipe
- PrivacyInfo not in podspec
- Intercept PagingMenuItem click and scroll to index manually
- Why collectionView.window is nil is the pagingController is not visible ? HOT 1
- how can I set font and selected font in swiftui? HOT 1
- for the swiftUI page view, when data changes, the UI can't be changed inside each page
- Add Border on all four sides of Menu Container HOT 1
- not visible selection of paging item (if its at the end of list) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parchment.