I’ve got a UIViewController called “MainViewController” which uses a custom class ‘CustomController’ to control one of it’s sub-views. The custom class instantiates UIButtons in code. How would I get these buttons to trigger methods in the MainViewController?
I’ve got a UIViewController called MainViewController which uses a custom class ‘CustomController’ to control
Share
I think delegation is the way to go there.
Define the protocol
CustomControllerDelegateinsideCustomController.hwith a method like this for example:Add a delegate property and synthesize it in the
.mfileNow when your button is pressed you simply call the delegate:
In your
MainViewControlleryou make it conform to the specified protocol and set the CustomControllers delegate like so:Now when the button is pressed, the
MainViewController‘s implementation of the specified method is called.