【发布时间】:2023-03-23 11:03:01
【问题描述】:
我正在尝试从显示它的 UIViewController 更新 iOS 上 ContainerView 的界面内容(UIViewController 嵌入在 UIView 中)。但是,ContainerView 不会更新其内容。强>
ContainerView 和 ViewController 与不同的类相关联。我可以使用以下几种方法在两个视图控制器之间传递数据:
- (void)displayStringInContainer:(NSString *)string
string 已成功从 ViewController 传递到 ContainerView,但是当我尝试在界面元素中显示该字符串时 - 没有任何反应(即使代码被调用):
self.buttonName.titleLabel.text = string;
我什至尝试在按钮上调用setNeedsDisplay,但没有任何反应。请注意,所有界面项都会发生这种情况。
以下是我如何从 ViewController 调用 ContainerView 上的方法:
ContainerViewController *cvc = [[ContainerViewController alloc] init];
[cvc displayStringInContainer:@"Text"];
我进行了很多搜索,但没有找到任何东西(也尝试查看 Apple Dev Site,但过去三天它一直处于关闭状态:P)。 有谁知道如何从另一个 ViewController 更新 ContainerViewController 的内容? 为什么这不起作用?一段时间以来,我一直在摸不着头脑。
【问题讨论】:
-
你的
UIViewController's视图如何让容器的视图? -
@JackyBoy ContainerView 被嵌入(通过故事板 segue)到我的
UIViewController内部的UIView中。我只是将 Container View 从对象库中拖到我的故事板上并将其连接起来。 -
我不使用 Storyboards,有几个原因。你刚刚又给了我一个。使用代码,你需要 30 秒才能做到这一点。对不起,我帮不了你。
-
在这种情况下,*cvc 似乎不是您故事板中的 ContainerViewController,对吧?你不应该使用你的容器视图连接到的属性吗?
-
@Stakenborg 是的,你是对的。 Container View(在我的故事板中)是一个
UIView,其中嵌入了一个 ViewController,因此我无法将它连接到 ContainerViewController(此处不兼容的类型)。
标签: ios objective-c uiviewcontroller container-view