When the user pressed an ‘add’ button a modal view pops up for them to enter information. I have a ‘cancel’ button in the top left of a navigation bar and I want it to dismiss the current view controller when it is pressed. How do I set an object as the class’s delegate? I understand creating protocols and implementing its methods but I cannot seem to make the delegate be set. When running the debugger my [self delegate] in the ‘add’ view controller is always nil.
When the user pressed an ‘add’ button a modal view pops up for them
Share
Are you spawning the modal viewController through a segue set up in your Storyboard? If so, then in the
prepareForSegue:method you would set the delegate there.On the other hand, if you are setting up the modal viewController entirely through code, then you would create an instance of the modal viewController then set it’s delegate.
Of course all this assumes you have defined a
delegateproperty on your modal viewController.