如何更新 splitViewController 中的详细视图?

发布于 2024-08-20 20:35:13 字数 521 浏览 6 评论 0原文

我正在尝试更新 splitViewController 中的详细视图。 这就是我尝试的:

//Get the application delegate
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];

//Get the masterViewController
MasterViewController *master = [delegate.splitViewController.viewControllers objectAtIndex:0];

到目前为止,这似乎工作正常。 然后我尝试通过执行以下操作来更新detailViewController中的标签:

master.detailViewController.myLabel.text = @"someText";

但这不起作用。

那么如何正确访问detailView中的outlet呢?

感谢您的帮助。

I'm trying to update a detailView in a splitViewController.
This is what I try:

//Get the application delegate
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];

//Get the masterViewController
MasterViewController *master = [delegate.splitViewController.viewControllers objectAtIndex:0];

This seems to work fine so far.
Then I try to update a label in the detailViewController by doing this:

master.detailViewController.myLabel.text = @"someText";

But this doesn't work.

So how is the right way to access the outlets of in the detailView?

Thanks for help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被你宠の有点坏 2024-08-27 20:35:13

定义DetailViewController;在您的示例中,detailViewController 是:

DetailViewController *detailViewController = [delegate.splitViewController.viewcontrollers objectAtIndex: 1];

Define the DetailViewController; in your example the detailViewController is:

DetailViewController *detailViewController = [delegate.splitViewController.viewcontrollers objectAtIndex: 1];

≈。彩虹 2024-08-27 20:35:13

您不应该进入另一个视图控制器并更改内容。相反,只需向 DetailViewController 发送一条消息,例如 [detailViewController setCurrentEntry:selectedEntry]。更好的是,使用通知或 KVO 让 DetailViewController 观察主列表中的选择。这样,两个视图控制器根本不需要互相引用;当您想要重新排列应用程序的布局,或者单独使用一个视图控制器(例如在模态视图中)时,这非常方便。为未来做好计划。

You shouldn't be reaching inside another view controller and changing things. Instead, simply send a message to the DetailViewController, e.g. [detailViewController setCurrentEntry:selectedEntry]. Better yet, use notifications or KVO to let the DetailViewController observe the selection in the master list. This way, the two view controllers need not refer to each other at all; this is handy when you want to rearrange your app's layout, or use one view controller in isolation, say, in a modal view. Plan for the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文