无法更改 splitviewcontroller 中的视图

发布于 2024-10-13 05:27:33 字数 694 浏览 7 评论 0原文

我试图通过单击模态视图中的按钮(一个人正在选择一个选项)来更改 splitview 控制器中的视图。我使用通知来完成此操作:

  1. 当在模式视图中单击按钮时,它会发出通知,然后自行关闭(解除):

    [[NSNotificationCenter defaultCenter] postNotificationName:@"launchProject" object:nil];

  2. 分割视图控制器内的 DetailViewController 正在侦听此通知,并切换 SVC 中的视图

-(void)launchProject:(NSNotification *)notification {
    Project* secondDetail2 = [[Project alloc] initWithNibName:nil bundle:nil];
    ProjectRootController* secondRoot2 = [[ProjectRootController alloc] initWithNibName:nil bundle:nil ]; 
    self.splitViewController.viewControllers =[NSArray arrayWithObjects: secondRoot2, secondDetail2 , nil];

}

I不明白为什么视图没有切换。欢迎对此提出任何建议。

I am trying to change the views in a splitview controller based upon clicking a button in a modalview (a person is selecting an option). I am using notifications to accomplish this:

  1. When the button is clicked in the modal view, it issues a notice, then closes (dismisses) itself:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"launchProject" object:nil];

  2. The DetailViewController inside the split view controller is listening for this notification, and switches out the views in the SVC

-(void)launchProject:(NSNotification *)notification {
    Project* secondDetail2 = [[Project alloc] initWithNibName:nil bundle:nil];
    ProjectRootController* secondRoot2 = [[ProjectRootController alloc] initWithNibName:nil bundle:nil ]; 
    self.splitViewController.viewControllers =[NSArray arrayWithObjects: secondRoot2, secondDetail2 , nil];

}

I don't understand why the views aren't switching out. Any advice on this will be welcome.

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

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

发布评论

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

评论(1

往日 2024-10-20 05:27:33

您没有显示所有代码,所以我猜测问题是对通知工作方式的误解。最初可能会令人困惑,但它非常简单。到目前为止,您已经有了:

[[NSNotificationCenter defaultCenter] postNotificationName:@"launchProject" object:nil]

,这很好。

但您还需要在

[[NSNotificationCenter defaultCenter]
 addObserver:self 
 selector:@selector(launchProject:) // selector should be your function name, launchProject
 name:@"launchProject" // notification name - must be same as what is given to postNotificatioName.
 object: nil];

某个地方,例如 init 函数中。

换句话说,postNotificationName:@"launchProject" 不会调用您的函数 launchProject。它将名为“launchProject”的通知放入 NSNotificationCenter defaultCenter 中。如果您不寻找该特定通知,那么什么都不会发生。

希望有帮助..

You haven't shown all the code, so I'm guessing the problem is a misunderstanding of how notifications work. It can be initially confusing, but it's very straightforward. So far, you have:

[[NSNotificationCenter defaultCenter] postNotificationName:@"launchProject" object:nil]

which is fine.

But you also need to have

[[NSNotificationCenter defaultCenter]
 addObserver:self 
 selector:@selector(launchProject:) // selector should be your function name, launchProject
 name:@"launchProject" // notification name - must be same as what is given to postNotificatioName.
 object: nil];

somewhere, like in an init function.

In other words, postNotificationName:@"launchProject" does NOT call your function launchProject. It puts a notification with the name "launchProject" into the NSNotificationCenter defaultCenter. If you're not looking for that particular notification, then nothing will happen.

Hope that helps..

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