gpt4 book ai didi

IOS Objective C 祖 parent 作为委托(delegate)

转载 作者:行者123 更新时间:2023-11-29 01:58:41 26 4
gpt4 key购买 nike

我有一个“GrandParentViewController”,它包含我的应用程序的所有方法。我有一个 subview “ParentViewController”,其中包含一些 subview “ChildVC”,我希望将其方法委托(delegate)给“GrandParentViewController”。我目前有一个来自 childVC >> parentVC >> GrandparentVC 的委托(delegate)链,但感觉不对。 IOS 的做法是什么?

最佳答案

似乎single responsibility principle在你的代码中被违反了。也许将 GrandParentViewController 拆分为多个类是个好主意?

还要确保您知道什么是 Objective-C 中的协议(protocol),以及应该如何使用它。

我不建议使用 NSNotifications,因为它很好,而且是为其他情况设计的,然后直接委托(delegate)。

关于IOS Objective C 祖 parent 作为委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30578086/

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