为什么我的应用程序在恢复后无法返回到我的详细信息视图? [英] Why doesn't my app return to my detail view when it's restored?

查看:137
本文介绍了为什么我的应用程序在恢复后无法返回到我的详细信息视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个简单的组织,我在Interface Builder故事板(而不是代码中)中配置了该组织。有一个导航视图控制器,其根视图控制器设置为我的主视图控制器。我的主视图包含一个表格,其中单元格将转换为详细视图控制器。

My app has a simple organization, which I've configured in an Interface Builder storyboard (not in code). There is a Navigation View Controller, which has its Root View Controller set to my Main View Controller. My Main View contains a table, where cells segue to a Detail View Controller.

当我在查看详细信息视图时暂停应用程序然后恢复它时,我是返回主视图,而不是详细信息视图。为什么会这样?

When I suspend the application while looking at the Detail View and then resume it, I'm returned to the Main View, rather than the Detail view. Why might this be?

详细信息:

我在Interface Builder中为导航视图控制器设置了恢复ID ,主视图控制器和详细视图控制器。我还尝试在表视图中添加一个Restoration ID,并使主视图控制器实现UIDataSourceModelAssociation。

I have set Restoration IDs in Interface Builder for the Navigation View Controller, the Main View Controller and the Detail View Controller. I've also tried adding a Restoration ID to the Table View and making the Main View Controller implement UIDataSourceModelAssociation.

我的应用程序从shouldRestoreApplicationState返回YES以及主视图和详细信息视图具有encode / decodeRestorableStateWithCoder方法。

My app is returning YES from shouldRestoreApplicationState and both the Main View and the Detail View have encode/decodeRestorableStateWithCoder methods.

我正在使用模拟器测试暂停/恢复:我运行应用程序,导航到详细信息视图,点击主页按钮,然后单击XCode中的停止按钮。要恢复,我正在从XCode再次运行应用程序。

I'm testing suspend/resume using the simulator: I run the app, navigate to the Detail View, hit the home button, and then click the stop button in XCode. To resume, I'm running the app again from XCode.

我看到挂起时的以下呼叫:

I see the following calls on suspend:

AppDelegate shouldSaveApplicationState
MainViewController encodeRestorableStateWithCoder
DetailViewController encodeRestorableStateWithCoder

简历:

AppDelegate shouldRestoreApplicationState
AppDelegate viewControllerWithRestorationIdentifierPath Navigation
AppDelegate viewControllerWithRestorationIdentifierPath Navigation/MainView
MainViewController viewDidLoad
AppDelegate viewControllerWithRestorationIdentifierPath Navigation/DetailView
MainViewController decodeRestorableStateWithCoder

In除了正在恢复的错误视图之外,还有其他奇怪之处:为什么详细信息视图的恢复标识符路径为Navigation / DetailView而不是Navigation / MainView / DetailView?导航视图控制器和详细视图控制器之间没有直接关系。它们在Interface Builder中的唯一连接是通过主视图中的segue。

In addition to the wrong view being restored, there's something else odd: Why is the Restoration Identifier Path for the Detail View "Navigation/DetailView" and not "Navigation/MainView/DetailView"? There is no direct relationship between the Navigation View Controller and the Detail View Controller. Their only connection in Interface Builder is via the segue from the Main View.

我是否配置错误?

我试过在Detail View中指定一个Restoration Class。当调用该恢复代码时,它会失败,因为UIStateRestorationViewControllerStoryboardKey未在编码器中设置。

I have tried assigning a Restoration Class to the Detail View. When that restoration code is invoked, it fails because the UIStateRestorationViewControllerStoryboardKey is not set in the coder.

这是我的项目的玩具版本,它复制了问题: https://github.com/WanderingStar/RestorationTest

Here's a toy version of my project which replicates the problem: https://github.com/WanderingStar/RestorationTest

I我正在尝试使用XCode版本5.0(5A1413)和iOS模拟器版本7.0(463.9.4),以防相关。

I'm trying this with XCode Version 5.0 (5A1413) and iOS Simulator Version 7.0 (463.9.4), in case those are relevant.

推荐答案

答案结果很简单:我没有打电话

The answer turned out to be simple: I was not calling

[super encodeRestorableStateWithCoder:coder];

在我的视图控制器中的encodeRestorableStateWithCoder:coder方法中(在解码中做同样的事情......) 。

in the encodeRestorableStateWithCoder:coder method in my View Controllers (and doing the same in decode...).

本教程帮助我逐步完成了流程的每一步,找出了我出错的地方:
http://useyourloaf.com/blog/2013/05/21/state-preservation-and -restoration.html

This tutorial helped me step through each step of the process, and find out where I'd gone wrong: http://useyourloaf.com/blog/2013/05/21/state-preservation-and-restoration.html

此外,事实证明Navigation / DetailView是预期的。导航视图控制器恢复其堆栈中的所有视图,然后将它们放回堆栈,而不是每个视图恢复堆栈中的后续视图。

Also, it turns out that "Navigation/DetailView" is what's expected. The Navigation View Controller restores all of the views in its stack and then puts them back into the stack, rather than each view restoring the later views in the stack.

这篇关于为什么我的应用程序在恢复后无法返回到我的详细信息视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆