正如我在上述主题中的问题所述,您通常需要满足哪些要求才能说“好的,我需要 encodeWithCoder:
和 initWithCoder:
实例化这个”?通常你可以将对象状态写入 NSUserDefaults
,所以我很好奇你们专家什么时候决定使用其中一个还是另一个?
最佳答案
initWithCoder:
在解压 XIB 文件时由操作系统使用;如果仔细观察,您会发现在 XIB 中创建的 View 不会调用 initWithFrame:
;他们将调用 initWithCoder:
。
关于iphone - 什么时候用encodeWithCoder : and initWithCoder: on the iPhone?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/809588/