gpt4 book ai didi

ios - UIButton 子类中的 presentModalViewController

转载 作者:行者123 更新时间:2023-11-28 23:16:07 25 4
gpt4 key购买 nike

iOS 编码的新手。我希望能够从 UIButton 子类中显示模式对话框。我之前在 UIViewController 中使用过 presentModalViewController。我如何从子类化的 UIButton 获取对 UIViewController 的引用?

我能以某种方式发现它的父级吗?在父 UIViewController 中实现一个协议(protocol),我可以将其设置为我的 UIButton 子类的委托(delegate)?

最佳答案

您应该能够像使用普通 UIButton 一样使用任何子类 UIButton。设置一个在按钮上触发的 Action ,该 Action 将调用 View Controller 上的方法。 View Controller 将处理推送模态视图 Controller 。

虽然有一些方法可以在按钮附加到 View 时从按钮中找出 View Controller ,但这是一种更好的方法。

关于ios - UIButton 子类中的 presentModalViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6314241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com