简体   繁体   中英

presentModalViewController inside a UIButton subclass

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 UIButton just as a normal UIButton . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM