Very new to iOS coding. I’d like to be able to display a modal dialog from inside a UIButton subclass. I’ve used presentModalViewController from inside a UIViewController before. How would I grab a reference to a UIViewController from my subclassed UIButton?
Can I somehow discover it’s parent? Implement a protocol in the parent UIViewController that I can set as a delegate on my UIButton subclass?
You should be able to use any subclassed
UIButtonjust as a normalUIButton. Setup an action that is triggered on the button which will call a method on the view controller. The view controller will deal with pushing the modal view controller.Although there are ways in which you can find out the view controller from the button when it is attached to a view, this is a better approach.