NavigationController 将子视图的执行与更高级别的视图同步

发布于 2024-12-09 07:26:08 字数 902 浏览 3 评论 0原文

我正在使用 NavigationController 来提供不同的视图。在一种情况下,我想使用 ChildView 从用户获取一些数据并将该数据返回到 ParentView。父视图使用 (IBAction) 方法中的 PushViewController 方法来响应 SegmentedController 上的选择:即 SegmentedController 上的不同按钮会推送不同的子视图。问题似乎是pushViewController方法分叉了一个新进程,而ParentView继续执行IBAction而不等待ChildView返回:即在ChildView viewWillAppear被调用之后。这是我的 NSLog 文件中的序列,显示了这种情况的发生。问题是我如何确保父级等到子级完成后才尝试访问数据。

eventAction: Child selected
ChildView: initWithNibName called
ChildView: viewDidLoad called
ParentView: viewWillDisappear called
ChildView: viewWillAppear called
ParentView: eventAction: after pushing ChildView: data = 0
ChildView: numberOfRowsInSection called
ParentView: viewDidDisappear called
ChildView: viewDidAppear called
ChildView: pickerView: didSelectRow: data = 3
ChildView: viewWillDisappear called
ParentView: viewWillAppear called
ChildView: viewDidDisappear called
ParentView: viewDidAppear called

I am using NavigationController to provide different views. In one case I want to use a ChildView to get some data from the user and return that data to the ParentView. The parent view uses the pushViewController method from within an (IBAction) method as it responds to a selection on a SegmentedController: that is the different buttons on the SegmentedController push different child views. The problem seems to be that the pushViewController method forks a new process and the ParentView keeps on executing the IBAction without waiting for the ChildView to return: i.e. after ChildView viewWillAppear is called. Here is the sequence from my NSLog file which shows this happening. The question is how can I ensure that the Parent waits until after the Child has finished before trying to access the data.

eventAction: Child selected
ChildView: initWithNibName called
ChildView: viewDidLoad called
ParentView: viewWillDisappear called
ChildView: viewWillAppear called
ParentView: eventAction: after pushing ChildView: data = 0
ChildView: numberOfRowsInSection called
ParentView: viewDidDisappear called
ChildView: viewDidAppear called
ChildView: pickerView: didSelectRow: data = 3
ChildView: viewWillDisappear called
ParentView: viewWillAppear called
ChildView: viewDidDisappear called
ParentView: viewDidAppear called

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文