https://github.com/iosdevgarg/container_views
https://github.com/iosdevgarg/container_views
containers containerview tableview uitableview uiviewcontroller
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/iosdevgarg/container_views
- Owner: iOSDevGarg
- Created: 2018-01-19T06:33:56.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-19T06:45:26.000Z (about 8 years ago)
- Last Synced: 2025-04-15T23:09:17.847Z (10 months ago)
- Topics: containers, containerview, tableview, uitableview, uiviewcontroller
- Language: Swift
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Container_Views
Add Other ViewControllers As subview in Container View
# Code Used
**Reference to Controller to be added as Subview**
private lazy var FirstObject: firstVC =
{
// Instantiate View Controller
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "firstVC") as! firstVC
// Add View Controller as Child View Controller
self.addChildViewController(viewController)
return viewController
}()
* Used Table Views As Subview in Second Controller Thus, Complex Designs can also be implemnted in same manner
# Adding subview to Container View
private func add(asChildViewController viewController: UIViewController)
{
// Configure Child View
viewController.view.frame = CGRect(x: 0, y: 0, width: self.firstContainer.frame.size.width, height: self.firstContainer.frame.size.height)
// Add Child View Controller
addChildViewController(viewController)
viewController.view.translatesAutoresizingMaskIntoConstraints = true
// Add Child View as Subview
firstContainer.addSubview(viewController.view)
// Notify Child View Controller
viewController.didMove(toParentViewController: self)
}
**Subviews Are being managed using code So, If required Added VC as Subview can aslo be Removed using**
private func remove(asChildViewController viewController: UIViewController)
{
// Notify Child View Controller
viewController.willMove(toParentViewController: nil)
secondContainer.willRemoveSubview(viewController.view)
// Remove Child View From Superview
viewController.view.removeFromSuperview()
// Notify Child View Controller
viewController.removeFromParentViewController()
}
# Expected Output
