0
我使用的Xcode 8和雨燕2.3斯威夫特保存和恢复的ViewController状态点击
我通过几个网站,这是关于状态恢复方法导游去:
https://www.raywenderlich.com/117471/state-restoration-tutorial
但我需要存储和恢复视图控制器的状态按钮点击传递确定的关键。
我不能在故事板中使用单一标识符,因为我需要保存同一个viewcontroller的许多实例,所以需要为每个实例使用不同的标识符,基于传递的密钥标识符,它应该只恢复相同视图的特定实例控制器
func sevNameVccBtnFnc(identifierKey :String)
{
// How to manually call encodeRestorableStateWithCoder
}
func revNameVccBtnFnc(identifierKey :String)->nameVcc
{
// How to manually call decodeRestorableStateWithCoder
}
的AppDelegate代码:
func application(application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool
{
return true
}
func application(application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool
{
return true
}
的ViewController代码:
class nameVcc: UIViewController, UIViewControllerRestoration
{
override func viewDidLoad()
{
super.viewDidLoad()
}
override func encodeRestorableStateWithCoder(coder: NSCoder)
{
print("encodeRestorableStateWithCoder")
super.encodeRestorableStateWithCoder(coder)
}
override func decodeRestorableStateWithCoder(coder: NSCoder)
{
print("decodeRestorableStateWithCoder")
super.decodeRestorableStateWithCoder(coder)
}
static func viewControllerWithRestorationIdentifierPath(identifierComponents: [AnyObject], coder: NSCoder) -> UIViewController?
{
print("viewControllerWithRestorationIdentifierPath")
let vc = nameVcc()
return vc
}
}