I implemented a Hamburger Menu which gets called when the user taps a BarButtonItem.
When the user clicks an index of the menu a delegate method gets called and selects the correct row:
func rowTapped(index: MenuIndex) {
let vc1 = storyboard?.instantiateViewController(withIdentifier: "VC1") as! VC!
// lazy loading
_ = vc1.self.view
vc1.transitionToNew(index)
}
And in my VC1 the ** transitionToNew** method gets called and selects the correct index:
(Let´s assume that the user tapped index 1 which is associated to .a)
func transitionToNew(_ index : MenuIndex) {
switch index {
case .a:
addSubviewToContainer(asChildViewController: childVC)
...
}
Now the childVC should be added into the scrollView of my VC1.
The childVC is instantiated lazy:
private lazy var childVC: ChildVC = {
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "ChildVC") as! ChildVC
return viewController
}()
To add the childVC into the scrollView the addSubViewToContainer method gets called in the switch-case statement:
private func addSubviewToContainer(asChildViewController viewController: UIViewController)
{
viewController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
viewController.view.frame = scrollView.bounds
addChildViewController(viewController)
scrollView.addSubview(viewController.view)
viewController.didMove(toParentViewController: self)
}
I know that views gets instantiated lazy (sadly) so we have to input something like
_ = self.view
(although its a stupid hack) to instantiate the view which indeed shows me that my scrollView got instantiated (at least I think that because the preview in the debugger shows me the view)
Can someone tell me without seeing all of the code why my the childVC is not added or displayed (!?) in my scrollView?
I got the correct frame, the scrollView should be instantiated at the moment the user taps an index.
UPDATE
I also have some navigation buttons which the user can select:
#IBAction func navigateToChildVC(_ sender: UIButton) {
addSubviewToContainer(asChildViewController: childVC)
)
}
It is calling the exact same method but here it is working.
It looks like with your implementation the scroll view cannot determine its content size, so setting it explicitly might fix your issue. Something in the lines of scrollView.contentSize = scrollView.bounds.size sets the content size so that it fills the scroll view in both dimensions - which might not be what you want for a scroll view, but that is a different discussion.
There is also no need to call addChildViewController when lazily creating the child view controller, it is enough to have it called in addSubviewToContainer.
Related
In working on this app with a TabBar at the bottom, NavBar at the top with a Segmented Control:
I have an issue where the View A (Segment One) with a UITableView, upon selecting a cell and displaying a new view with more details, when I click back, the Segmented control at the top will disappear and the TableView from View A will be pushed up.
This doesn't always happen - sometimes after many tries or sometimes just one. I haven't found any correlation to what's causing it.
I have found that if I select View B from the segmented Control, then back to View A, then click on one of the table cells to get to the details screen and then click back, 100% of the time the Top Nav Bar disappears with the segmented control.
TabBarItemOneViewController
let segmentOneVC: SegmentOneViewController
let segmentTwoVC: SegmentTwoViewController
var currentViewController: UIViewController
let viewControllerYLoc = 60 // statusBarHeight + topBarHeight
let viewWidth = Helper.getViewWidth()
let tabBarHeight = 40
func pressedSegItem(segControl: UISegmentedControl){
let viewControllerHeight = Int(self.view.frame.height)
let viewFrame = CGRect(x: 0, y: viewControllerYLoc, width: Int(viewWidth), height: viewControllerHeight)
let selectedIndex = segControl.selectedSegmentIndex
previouslySelectedMyLoadsIndex = selectedIndex
self.currentViewController.removeFromParentViewController()
if(selectedIndex == 0){
currentViewController = segmentOneVC
}
else if(selectedIndex == 1){
currentViewController = segmentTwoVC
}
self.view.addSubview(self.currentViewController.view)
self.currentViewController.didMove(toParentViewController: self)
}
public init() {
segmentOneVC = SegmentOneViewController(nibName: nil, bundle: nil)
segmentTwoVC = SegmentTwoViewController(nibName: nil, bundle: nil)
if(previouslySelectedIndex == 0){
currentViewController = segmentOneVC
}
else{
currentViewController = segmentTwoVC
}
super.init(nibName: nil, bundle: nil)
self.calculateItems()
self.addSegmentedControl()
let viewControllerHeight = (Int(self.view.frame.height) - viewControllerYLoc) - tabBarHeight
let viewFrame = CGRect(x: 0, y: viewControllerYLoc, width: Int(viewWidth), height: viewControllerHeight)
self.currentViewController.view.frame = viewFrame
self.addChildViewController(segmentOneVC)
self.addChildViewController(segmentTwoVC)
self.view.addSubview(self.currentViewController.view)
self.currentViewController.didMove(toParentViewController: self)
}
SegmentOneViewController (note: SegmentTwoViewController is identical)
let cellReuseIdentifier = "ItemDetailTableViewCell"
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let row = indexPath.row
let dataItem = self.dataArray[row]
let itemDetailVC = ItemDetailViewController()
itemDetailVC.dataItem = dataItem
self.present(itemDetailVC, animated: true, completion: nil)
}
func addTableView(){
self.tableView = UITableView()
tableView.register(ItemDetailTableViewCell.self, forCellReuseIdentifier: self.cellReuseIdentifier)
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
tableView.frame = CGRect(x: 0, y: 0, width: Int(viewWidth), height: (Int(self.view.frame.height) - bottomOfTopNavBar) - heightOfTabBar)
self.view.addSubview(tableView)
}
override func viewDidAppear(_ animated: Bool){
super.viewDidAppear(animated)
loadData()
tableView.dataSource = self
tableView.delegate = self
}
override func viewDidLoad() {
super.viewDidLoad()
addTableView()
}
ItemDetailViewController
// Connected to a back button in a top Navigation Bar
func goBack(){
self.dismiss(animated: false, completion: nil)
}
Nice graphics BTW... that illustration make it much easier to understand your problem.
Also BTW, I'm an Obj-C person, still learning the nuances of Swift, so please let me know if my syntax or otherwise is incorrect. I'm also relatively inexperienced in using container VC's.
I've written my response in two parts.
The First Part is my attempt to solve your problem.
The Second Part is my suggestion for an alternative for you to consider.
First Part
This is my understanding of the order/sequence of execution in your code...
Parent View with Segmented Control
public init () : on instantiation of the parent view controller, two child VCs (segmentOneVC and segmentTwoVC) are instantiated and depending on previous selection are assigned as currentViewController. Then you add a segmented control to the TabBarItemOneViewController.
User taps a segmented control.
Depending on user input, either the SegmentOneViewController or SegmentTwoViewController view is added as a subview to the TabBarItemOneViewController.view. (Note that this is also done when the VC is initialised.)
Child View
override func viewDidLoad() : once the view did load, you call the function addTableView.
func addTableView() : in this custom function you instantiate your table view and place it within the SegmentOneViewController, which is itself I assume a UIViewController.
override func viewDidAppear(_ animated: Bool) : you call the custom function loadData and set your table view data source and delegate.
Back Button
User taps the back button.
Child VC is dismissed and the TabBarItemOneViewController becomes the active view on screen.
Let's look at what does not happen in the view controller lifecycle when the back button is pressed... Item 1 in the list.
This may explain the inconsistency.
Try this... run the app, tap the tab control to take you to TabBarItemOneViewController. Don't tap the segmented control. Tap a line in your table view. Tap the back button in your child VC. I'd take a guess your segmented control is still there.
Now try this... run the app, tap the tab control to take you to TabBarItemOneViewController. Tap the segmented control. Tap a line in your table view. Tap the back button in your child VC. I'd take a guess your segmented control is no longer there.
Why? Because the custom function pressedSegItem that I assume has a target action assigned to the segmented control, will overwrite your init, which is where you add the segmented control into the tab bar view controller.
So by way of example, try placing the code to instantiate your segmented control instead in an override function of viewWillAppear of the TabBarItemOneViewController VC.
So a couple of concepts to think about...
lazy loading to save memory allocation - only instantiate the objects you need when the user specifically requests that function in the app;
order of execution of each function in the UIViewController lifecycle; and
which functions are executed once and which are executed each time your view becomes first responder / the active view.
Some reading recomendations:
This SO question titled :Looking to understand the iOS UIViewController lifecycle" presents a lot of good information, but understand that some of the information is incorrect due to deprecation of viewDidUnload from iOS 6.
Which is why you should always go to the Apple documentation for UIViewController to refer to the latest API reference.
Second Part
By providing this alternative, I'm not suggesting that your approach is incorrect, however I am suggesting an alternative for you to consider.
I've always used tab bar controllers to change views and segmented controls to filter data sets or change the appearance of the current view.
Think about using a UISegmentedControl to manage or adjust the data set within only one table view. This will alleviate the need for multiple view controllers and the juggling act of managing these.
For example, when writing your data source and delegate methods / functions for your tabel view, you can include the following code to ensure the table view loads and responds accordinagly:
let selectedIndex = segControl.selectedSegmentIndex
if(selectedIndex == 0) {
rowHeight = 20 'for example
} else {
rowHeight = 30 'for example
}
Then you'd need to relaod your table view to effect the changes.
I got an PageViewController which loads two "child "ViewControllers in order to let the user "swipe" through them. I don't want this swipe gesture , but instead I want to have a function inside my ViewController which allows me to use setViewControllers in the PageViewController.
I tried using protocols but even that didn't work out.
I would realy appreciate any help or suggestions on how I could accomplish that. Thanks!
To access setViewControllers from your child view controllers, you will need your child view controllers to be aware of their parent PageViewController. To do so, start by making a Protocol (I know you've said you've tried Protocols, but please please see my method through). This Protocol will ensure that every child view controller has a reference to the parent PageViewController.
protocol PageObservation: class {
func getParentPageViewController(parentRef: PageViewController)
}
Ensure that your child view controllers adhere to the PageObservation Protocol.
class Child1ViewController: UIViewController, PageObservation {
var parentPageViewController: PageViewController!
func getParentPageViewController(parentRef: PageViewController) {
parentPageViewController = parentRef
}
}
class Child2ViewController: UIViewController, PageObservation {
var parentPageViewController: PageViewController!
func getParentPageViewController(parentRef: PageViewController) {
parentPageViewController = parentRef
}
}
In your PageViewController, as you create each child view controller, cast them to the PageObservation type and pass a reference of the parent PageViewController. I use an array called orderViewControllers to create my pages. My UIPageViewControllerDataSource delegate methods uses it to know which pages to load but that is irrelevant to this example, I just thought I'd let you know in case you have a different way of creating your pages.
class PageViewController: UIPageViewController {
var orderedViewControllers: [UIViewController] = []
//creating child 1
//i am using storyboard to create the child view controllers, I have given them the identifiers Child1ViewController and Child2ViewController respectively
let child1ViewController = UIStoryboard(name: "Main", bundle: nil) .
instantiateViewController(withIdentifier: "Child1ViewController")
let child1WithParent = child1ViewController as! PageObservation
child1WithParent.getParentPageViewController(parentRef: self)
orderedViewControllers.append(child1ViewController)
//creating child 2
let child2ViewController = UIStoryboard(name: "Main", bundle: nil) .
instantiateViewController(withIdentifier: "Child2ViewController")
let child2WithParent = child2ViewController as! PageObservation
child2WithParent.getParentPageViewController(parentRef: self)
orderedViewControllers.append(child2ViewController)
}
Now inside your child view controllers, you have access to setViewControllers. For example, if I want to call setViewControllers in the child1ViewController, I have created a func called accessSetViewControllers() where I access the setViewControllers:
class Child1ViewController: UIViewController, PageObservation {
var parentPageViewController: PageViewController!
func getParentPageViewController(parentRef: PageViewController) {
parentPageViewController = parentRef
}
func accessSetViewControllers() {
parentPageViewController.setViewControllers( //do what you need )
}
}
On a side note, despite what other answers above have said, you can set dataSource to whatever you like. I sometimes set dataSource to nil to prevent the user from swiping away from a screen before doing something and then add the dataSource back to allow them to continue swiping.
Don't set dataSource. When it's nil, then gestures won't work.
https://developer.apple.com/reference/uikit/uipageviewcontroller
When defining a page view controller interface, you can provide the content view controllers one at a time (or two at a time, depending upon the spine position and double-sided state) or as-needed using a data source. When providing content view controllers one at a time, you use the setViewControllers(_:direction:animated:completion:) method to set the current content view controllers. To support gesture-based navigation, you must provide your view controllers using a data source object.
Simplistic approach... remove the inbuilt gesture recogniser in viewDidLoad of pageViewController:
for view in self.pageViewController!.view.subviews {
if let subView = view as? UIScrollView {
subView.scrollEnabled = false
}
}
Then add your own gesture below it. i just happened to be working with double tap at the moment but you could make it swipe left, swipe right easy enough:
let doubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didDoubleTap))
doubleTap.numberOfTapsRequired = 2
doubleTap.delaysTouchesBegan = true
self.addGestureRecognizer(doubleTap)
and the gesture function with your code:
func didDoubleTap(gesture: UITapGestureRecognizer) {
//... stuff
}
There is a library I really enjoy that you could find here (https://github.com/pixyzehn/MediumMenu).
Essentially it does the following:
The menu in the back is actually a UIViewController. If we delve into the source code, we'll find the following very important code:
public init(items: [MediumMenuItem], forViewController: UIViewController) {
self.init()
self.items = items
height = screenHeight - 80 // auto-calculate initial height based on screen size
frame = CGRect(x: 0, y: 0, width: screenWidth, height: height)
contentController = forViewController
menuContentTableView = UITableView(frame: frame)
menuContentTableView?.delegate = self
menuContentTableView?.dataSource = self
menuContentTableView?.showsVerticalScrollIndicator = false
menuContentTableView?.separatorColor = UIColor.clearColor()
menuContentTableView?.backgroundColor = menuBackgroundColor
addSubview(menuContentTableView!)
if panGestureEnable {
let pan = UIPanGestureRecognizer(target: self, action: #selector(MediumMenu.didPan(_:)))
contentController?.view.addGestureRecognizer(pan)
}
let menuController = UIViewController()
menuController.view = self
UIApplication.sharedApplication().delegate?.window??.rootViewController = contentController
UIApplication.sharedApplication().delegate?.window??.insertSubview(menuController.view, atIndex: 0)
}
The first few lines aren't really important, but the very last lines (the ones dealing with the UIApplication.sharedApplication().delegate?.window?? are the key to this library working, but they also limit the library.
According to those lines, we're making the UIViewController that we want the menu for to be the rootViewController and then we add the menu view to the window at the 0 index (I'm guessing this is what puts it in the back, behind the contentController).
The problem with the library:
The library only works if you want the menu on the initial view controller. In a sense, only if the contentController is already the rootViewController. It'll actually function for me in my app, but I can't segue back to my original UIViewController because it isn't in the hierarchy anymore.
I have a scenario where I have a Login View Controller, and when you successfully login, I segue you to my UINavigationController on which I want the menu. The first clear sign of an issue is that I get the complaint "Warning: Attempt to present UINavigationController on LoginViewController whose view is not in the window hierarchy!" Obviously, it isn't in the window hierarchy because I'm reassigning the rootViewController.
I don't know how to fix this. Is there a way to have this functionality work when the UIViewController I want the menu on isn't the initial view controller?
Short answer is: Yes.
This can be implemented with by assigning a UIViewControllerTransitioningDelegate to the ViewController containing the list-menu and implementing the interactionControllerForPresentation() and interactionControllerForDismissal() methods. You don't have to touch the UIWindow (directly).
You could just change this part about the existing library, but from the looks of it it's just a TableView with a fancy transition. You could easily implement this yourself.
Check out Apple's API Reference on interactive transitions and this tutorial by Ray Wenderlich for a hands on example.
So it is clear your scenario is:
rootViewController = a UINavigationController
the rootViewController of UINavigationController is the LoginController
When someone login succeed, the navigationController push(or segue) to a menuController
or
rootViewController is the LoginController
When someone login succeed, it will present the menuController
So the key point is to get a menuController and not set it to the rootViewController of the app.
Here is the code which i made some change to fit your requirement.
https://github.com/Moonsownner/MediumMenu-master
What did i do:
MediumMenu actually is a UIView, we have to create a controller to contain it so that to make the transition. So i make a new class named MediumMenuController. And you can see i move function showMenu into MediumMenuController. So if someone want to show the menu manually, the target must be a MediumMenuController not the previous NavigationController. And the MediumMenuController will contain your business controller which you send in into the init function of MediumMenuController.
class MediumMenuController: UIViewController {
let menuView: MediumMenu
let child: UIViewController
init(items: [MediumMenuItem], childController: UIViewController){
self.menuView = MediumMenu(items: items, forViewController: childController)
self.child = childController
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(menuView)
addChildViewController(child)
self.view.addSubview(child.view)
child.view.frame = UIScreen.mainScreen().bounds
child.didMoveToParentViewController(self)
}
func showMenu() {
menuView.show()
}
}
I delete the code in MediumMenu.
let menuController = UIViewController(); menuController.view = self
UIApplication.sharedApplication().delegate?.window??.rootViewController
= contentController UIApplication.sharedApplication().delegate?.window??.insertSubview(menuController.view,
atIndex: 0)
and create a new controller named MediumMenuController to add the MediumMenu and the other controllers views to it.
Maybe it is not clear by saying above. The code can show you the detail. Good luck.
You can achieve it by following steps.
(i) Make LoginViewController as your rootViewController.
(ii) When user signs in successfully, redirect user to Home Screen. That is your first screen that you want to show after successfully logged in.
(iii) You can make a parent class of UIViewControllers where you want to show the menu.
(iv) After that, when you initialize any UIViewController, parent class will call public init(items: [MediumMenuItem], forViewController: UIViewController) method and in that you can replace last two lines with below code.
self.view.insertSubview(menuController.view, atIndex: 0)
(v) On tapping sign out button, you can simply dismiss presented view controller, so LoginViewController will always be there.
Hope this helps!
My view controller hierarchy is the following:
The entry point is a UINavigationController, whose root view controller is a usual UITableViewController. The Table View presents a list of letters.
When the user taps on a cell, a push segue is triggered, and the view transitions to ContainerViewController. It contains an embedded ContentViewController, whose role is to present the selected letter on screen.
The Content View Controller stores the letter to be shown as a property letter: String, which should be set before its view is pushed on screen.
class ContentViewController: UIViewController {
var letter = "-"
#IBOutlet private weak var label: UILabel!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
label.text = letter
}
}
On the contrary, the Container View Controller should not know anything about the letter (content-unaware), since I'm trying to build it as reusable as possible.
class ContainerViewController: UIViewController {
var contentViewController: ContentViewController? {
return childViewControllers.first as? ContentViewController
}
}
I tried to write prepareForSegue() in my Table View Controller accordingly :
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let containerViewController = segue.destinationViewController as? ContainerViewController {
let indexPath = tableView.indexPathForCell(sender as! UITableViewCell)!
let letter = letterForIndexPath(indexPath)
containerViewController.navigationItem.title = "Introducing \(letter)"
// Not executed:
containerViewController.contentViewController?.letter = letter
}
}
but contentViewController is not yet created by the time this method is called, and the letter property is never set.
It is worth mentioning that this does work when the segue's destination view controller is set directly on the Content View Controller -- after updating prepareForSegue() accordingly.
Do you have any idea how to achieve this?
Actually I feel like the correct solution is to rely on programmatic instantiation of the content view, and this is what I chose after careful and thorough thoughts.
Here are the steps that I followed:
The Table View Controller has a push segue set to ContainerViewController in the storyboard. It still gets performed when the user taps on a cell.
I removed the embed segue from the Container View to the ContentViewController in the storyboard, and I added an IB Outlet to that Container View in my class.
I set a storyboard ID to the Content View Controller, say… ContentViewController, so that we can instantiate it programmatically in due time.
I implemented a custom Container View Controller, as described in Apple's View Controller Programming Guide. Now my ContainerViewController.swift looks like (most of the code install and removes the layout constraints):
class ContainerViewController: UIViewController {
var contentViewController: UIViewController? {
willSet {
setContentViewController(newValue)
}
}
#IBOutlet private weak var containerView: UIView!
private var constraints = [NSLayoutConstraint]()
override func viewDidLoad() {
super.viewDidLoad()
setContentViewController(contentViewController)
}
private func setContentViewController(newContentViewController: UIViewController?) {
guard isViewLoaded() else { return }
if let previousContentViewController = contentViewController {
previousContentViewController.willMoveToParentViewController(nil)
containerView.removeConstraints(constraints)
previousContentViewController.view.removeFromSuperview()
previousContentViewController.removeFromParentViewController()
}
if let newContentViewController = newContentViewController {
let newView = newContentViewController.view
addChildViewController(newContentViewController)
containerView.addSubview(newView)
newView.frame = containerView.bounds
constraints.append(newView.leadingAnchor.constraintEqualToAnchor(containerView.leadingAnchor))
constraints.append(newView.topAnchor.constraintEqualToAnchor(containerView.topAnchor))
constraints.append(newView.trailingAnchor.constraintEqualToAnchor(containerView.trailingAnchor))
constraints.append(newView.bottomAnchor.constraintEqualToAnchor(containerView.bottomAnchor))
constraints.forEach { $0.active = true }
newContentViewController.didMoveToParentViewController(self)
}
} }
In my LetterTableViewController class, I instantiate and setup my Content View Controller, which is added to the Container's child view controllers. Here is the code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let containerViewController = segue.destinationViewController as? ContainerViewController {
let indexPath = tableView.indexPathForCell(sender as! UITableViewCell)!
let letter = letterForIndexPath(indexPath)
containerViewController.navigationItem.title = "Introducing \(letter)"
if let viewController = storyboard?.instantiateViewControllerWithIdentifier("ContentViewController"),
let contentViewController = viewController as? ContentViewController {
contentViewController.letter = letter
containerViewController.contentViewController = contentViewController
}
}
}
This works perfectly, with an entirely content-agnostic container view controller. By the way, it used to be the way one instantiated a UITabBarController or a UINavigationController along with its children, in the appDidFinishLaunching:withOptions: delegate method.
The only downside of this I can see: the UI flow ne longer appears explicitly on the storyboard.
The only way I can think of is to add delegation so that your tableViewController implements a protocol with one method to return the letter; then you have containerViewController setting its childViewController (the contentViewController) delegate to its parent. And the contentViewController can finally ask its delegate for the letter.
At your current solution the presenting object itself is responsible for working both with the "container" and the "content", it doesn't have to be changed, but such solution not only has the issues like the one you described, but also makes the purpose of the "container" not very clear.
Look at the UIAlertController: you are not configuring its child view controller directly, you are not even supposed to know it exists when using the alert controller. Instead of configuring the "content", you are configuring the "container" which is aware of the content interfaces, lifecycle and behavior and doesn't expose it. Following this approach you achieve a properly divided responsibility of the container and content, minimal exposure of the "content" allows you to update the "container" without a need to update the way it is used.
In short, instead of trying to configure everything from a single place, make it so you configure only the "container" and let it configure the "content" when and where it is needed. E.g. in the scenario you described the "container" would set data for the "content" whenever it initializes the child controllers. I'm using "container" and "content" instead of ContainerViewController and ContentViewController because the solution is not strictly based on the controllers because you might as well replace it wth NSObject + UIView or UIWindow.
I have a View controller with an embedded Container View plus a controller
The Container View hosts a UIPageViewController
The View controller has a button, if its clicked I want to update a label in the current displayed page managed by the UIPageView Controller
I am getting the ContainerView Controller with this approach
#IBAction func sendButtonTouched(sender: AnyObject) {
if let vc = self.childViewControllers.last as? ContainerViewController{
vc.pageViewController.view.backgroundColor = UIColor.blueColor()
I get the UIPageViewController and set the color but it does not update
also if go deeper into the rabbit hole to get my currently viewed page I am able to get and set all values but my view never updates
what I really want to do is something like this
#IBAction func sendButtonTouched(sender: AnyObject) {
if let vc = self.childViewControllers.last as? ContainerViewController{
vc.pageViewController.view.backgroundColor = UIColor.blueColor()
print("make it blue baby")
if let pageItemController = vc.getCurrentViewController(){
print(pageItemController.indexLabel.text)
pageItemController.message = self.messageTextView.text
pageItemController.messageImage.image = UIImage()
pageItemController.reloadInputViews()
}
}
}
and in ContainerViewController
func getCurrentViewController()-> MIPViewController?
{
print("\(self.pageViewController.viewControllers!.count) view controllers")
if let vc = self.pageViewController.viewControllers!.first as? PageItemViewController
{
if vc.index < mipCount
// must be a MIPViewController
{
return vc as? MIPViewController
}
}
return nil
}
in my console output i see
make it blue baby
1 view controllers
Optional("This is a message of the number 0")
Optional("")
so everything is called but as stated no view ever updates
I am probably missing something really basic here, so thank you for your help
I also checked other questions e.g. Access Container View Controller from Parent iOS
but afaik using the childViewControllers is also valid