无法更改 splitviewcontroller 中的视图
我试图通过单击模态视图中的按钮(一个人正在选择一个选项)来更改 splitview 控制器中的视图。我使用通知来完成此操作:
当在模式视图中单击按钮时,它会发出通知,然后自行关闭(解除):
[[NSNotificationCenter defaultCenter] postNotificationName:@"launchProject" object:nil];
分割视图控制器内的 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:
When the button is clicked in the modal view, it issues a notice, then closes (dismisses) itself:
[[NSNotificationCenter defaultCenter] postNotificationName:@"launchProject" object:nil];
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有显示所有代码,所以我猜测问题是对通知工作方式的误解。最初可能会令人困惑,但它非常简单。到目前为止,您已经有了:
[[NSNotificationCenter defaultCenter] postNotificationName:@"launchProject" 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
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 theNSNotificationCenter defaultCenter
. If you're not looking for that particular notification, then nothing will happen.Hope that helps..