NavigationController 将子视图的执行与更高级别的视图同步
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论