• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 使用唯一键的 NSKeyedarchiver 警告

[复制链接]
菜鸟教程小白 发表于 2022-12-12 18:49:09 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在测试保存/状态恢复时,当我使用主页按钮将我的应用程序置于后台时,我收到了多个类似的日志警告。

2014-02-13 20:13:08.275 FlowTrak[16777:60b] *** NSKeyedArchiver warning: replacing existing 
value for key 'UIStateRestorationViewControllerStoryboard'; probable duplication of encoding 
keys in class hierarchy

应用程序在设备上运行良好,所有状态恢复/保存都可以正常工作,但我很想摆脱这些警告。那里没有关于这些警告的大量信息,但从我所阅读的内容来看,只要我为我要保留的每个 UI 项目使用唯一键,我应该会很好。

有什么想法可以解决这个问题吗?谢谢。

这是我的代码:

// Restoration of text fields
-(void)encodeRestorableStateWithCoderNSCoder *)coder
{
    // start level text
    [coder encodeObject:_startLevel.text forKey"startText"];
    [super encodeRestorableStateWithCoder:coder];

    // stop level text
    [coder encodeObject:_stopLevel.text forKey"stopText"];
    [super encodeRestorableStateWithCoder:coder];

    // start time label
    [coder encodeObject:_startTimeLabel.text forKey"startTimeText"];
    [super encodeRestorableStateWithCoder:coder];

    // stop time label
    [coder encodeObject:_stopTimeLabel.text forKey"stopTimeText"];
    [super encodeRestorableStateWithCoder:coder];

    // minute rate label
    [coder encodeObject:_minuteRateLabel.text forKey"minuteRateText"];
    [super encodeRestorableStateWithCoder:coder];

    // start segmented control
    [coder encodeInteger:self.startFractionControl.selectedSegmentIndex forKey"startIndex"];
    [super encodeRestorableStateWithCoder:coder];

    // stop segmented control
    [coder encodeInteger:self.stopFractionControl.selectedSegmentIndex forKey"stopIndex"];
    [super encodeRestorableStateWithCoder:coder];

    // start button state
    [coder encodeBool:self.start.enabled forKey"startButtonState"];
    [super encodeRestorableStateWithCoder:coder];

    // stop button state
    [coder encodeBool:self.stop.enabled forKey"stopButtonState"];
    [super encodeRestorableStateWithCoder:coder];

    // calculate button state
    [coder encodeBool:self.calculate.enabled forKey"calculateButtonState"];
    [super encodeRestorableStateWithCoder:coder];

    // resume button state
    [coder encodeBool:self.resume.enabled forKey:@"resumeButtonState"];
    [super encodeRestorableStateWithCoder:coder];

    // tank selector segmented control
    [coder encodeInteger:self.tankControl.selectedSegmentIndex forKey:@"tankIndex"];
    [super encodeRestorableStateWithCoder:coder];

    // start time for equation
    [coder encodeDouble:startTime forKey:@"startTimeEquation"];
    [super encodeRestorableStateWithCoder:coder];

    // stop time for equation
    [coder encodeDouble:stopTime forKey:@"stopTimeEquation"];
    [super encodeRestorableStateWithCoder:coder];

    // start segmented control for equation
    [coder encodeObject:startFractions forKey:@"startFractionsEquation"];
    [super encodeRestorableStateWithCoder:coder];

    // stop segmented control for equation
    [coder encodeObject:stopFractions forKey:@"stopFractionsEquation"];
    [super encodeRestorableStateWithCoder:coder];

    // tank selector segmented control for equation
    [coder encodeBool:bigTank forKey:@"bigTankEquation"];
    [super encodeRestorableStateWithCoder:coder];


}

-(void)decodeRestorableStateWithCoderNSCoder *)coder
{
    // start level text
    _startLevel.text = [coder decodeObjectForKey:@"startText"];
    [super decodeRestorableStateWithCoder:coder];

    // stop level text
    _stopLevel.text = [coder decodeObjectForKey:@"stopText"];
    [super decodeRestorableStateWithCoder:coder];

    // start time label
    _startTimeLabel.text = [coder decodeObjectForKey:@"startTimeText"];
    [super decodeRestorableStateWithCoder:coder];

    // stop time label
    _stopTimeLabel.text = [coder decodeObjectForKey:@"stopTimeText"];
    [super decodeRestorableStateWithCoder:coder];

    // minute rate label
    _minuteRateLabel.text = [coder decodeObjectForKey:@"minuteRateText"];
    [super decodeRestorableStateWithCoder:coder];

    // start segmented control
     self.startFractionControl.selectedSegmentIndex = [coder decodeIntegerForKey:@"startIndex"];
    [super decodeRestorableStateWithCoder:coder];

    // stop segmented control
    self.stopFractionControl.selectedSegmentIndex = [coder decodeIntegerForKey:@"stopIndex"];
    [super decodeRestorableStateWithCoder:coder];

    // start button state
    self.start.enabled = [coder decodeBoolForKey:@"startButtonState"];
    [super decodeRestorableStateWithCoder:coder];

    // stop button state
    self.stop.enabled = [coder decodeBoolForKey:@"stopButtonState"];
    [super decodeRestorableStateWithCoder:coder];

    // calculate button state
    self.calculate.enabled = [coder decodeBoolForKey:@"calculateButtonState"];
    [super decodeRestorableStateWithCoder:coder];

    // resume button state
    self.resume.enabled = [coder decodeBoolForKey:@"resumeButtonState"];
    [super decodeRestorableStateWithCoder:coder];

    // tank selector segmented control
    self.tankControl.selectedSegmentIndex = [coder decodeIntegerForKey:@"tankIndex"];
    [super decodeRestorableStateWithCoder:coder];

    // start time for equation
    startTime = [coder decodeDoubleForKey:@"startTimeEquation"];
    [super decodeRestorableStateWithCoder:coder];

    // stop time for equation
    stopTime = [coder decodeDoubleForKey:@"stopTimeEquation"];
    [super decodeRestorableStateWithCoder:coder];

    // start segmented control for equation
    startFractions = [coder decodeObjectForKey:@"startFractionsEquation"];
    [super decodeRestorableStateWithCoder:coder];

    // stop segmented control for equation
    stopFractions = [coder decodeObjectForKey:@"stopFractionsEquation"];
    [super decodeRestorableStateWithCoder:coder];

    // calculate button state
    bigTank = [coder decodeBoolForKey:@"bigTankEquation"];
    [super decodeRestorableStateWithCoder:coder];

}



Best Answer-推荐答案


你为什么要多次调用 super 的实现?只调用一次!

关于ios - 使用唯一键的 NSKeyedarchiver 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21770307/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap