gpt4 book ai didi

ios - 从另一个容器调用一个容器中的函数

转载 作者:行者123 更新时间:2023-11-30 13:51:20 25 4
gpt4 key购买 nike

我有 mainViewController.swift,它有 2 个嵌入式容器。当我按下 container2 中的按钮时,我需要使 container1 中的按钮更改其标签。

container2ViewController 中的以下我糟糕的发明代码并没有削减它。

((self.MainController as! ViewController).container1 as! Container1ViewController).yesBt.setTitle("Exit", forState: UIControlState.Normal)

我在左边看到黄色三角形,并显示消息:
从 UIView 转换为不相关类型 Continer1ViewController 总是失败

我希望一定有更好的方法来做到这一点。

最佳答案

要在非直接连接的对象之间发送消息,可以使用 NSNotification。需要更改的容器会监听通知,该通知是在点击其他容器的按钮时发布的。

关于ios - 从另一个容器调用一个容器中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34235288/

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