When the view controller is presented within a tab bar controller, you can access the tab bar controller like this:
When the view controller is part on an navigation stack, you can access the navigation controller like this:
Adding/removing a child view controller
To add a child view controller:
To remove a child view controller:
Create an instance
Instantiate from a Storyboard
With an Identifier:
Give the scene a Storyboard ID within the identity inspector of the storyboard.
Instantiate in code:
Instantiate an initial viewcontroller:
Within the storyboard select the view controller, then select the attribute inspector, check the "Is Initial View Controller" box.
Set the view programmatically
Subclassing UIControl gives us access to the following methods:
beginTrackingWithTouch is called when the finger first touches down within the control's bounds.
continueTrackingWithTouch is called repeatedly as the finger slides across the control and even outside of the control's bounds.
endTrackingWithTouch is called when the finger lifts off the screen.
This is how the view controller is set up to be the delegate and respond to touch events from our custom control.
Alternate methods of achieving the same result without subclassing include adding a target or using a gesture recognizer.
It is not necessary to use a delegate with these methods if they are only being used within the custom control itself. We could have just added a print statement to show how the events are being called. In that case, the code would be simplified to
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0