我正在尝试通过执行以下操作来制作我的UIViewController子类的副本:
BookViewController *bookVC = [catalogFlatViewController copy];并且我有以下错误:
'-[BookViewController copyWithZone:]: unrecognized selector sent to instance 0x8e5f00'发布于 2012-04-10 12:48:28
UIViewController不符合NSCopying。如果你想复制一份,你必须使用NSCoding
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:controller];
UIViewController *newController = [NSKeyedUnarchiver unarchiveObjectWithData:archive];如果您向视图控制器添加了新的ivar,则必须覆盖NSCoding方法(encodeWithCoder:和initWithCoder:)才能正确地序列化和反序列化这些方法。参见Archives and Serializations Programming Guide。
顺便说一句,这基本上就是nib文件的工作原理。
发布于 2012-04-10 13:05:13
请参阅以下帖子中的@Caleb答案:
iOS copyWithZone unrecognized selector only when using device
Caleb的答案如下
UIViewController不实现NSCopying协议。除非您在自己的UIViewController子类中实现了NSCopying,否则视图控制器不会响应
-copyWithZone:。
有关更多信息:您可能想要参考UIViewController class reference。
但我建议您不要实现NSCopying协议参考,因为@RobNapier在Implementing NSCopying (or NSCopyObject() considered harmful)上发表了一篇非常好且内容丰富的文章
希望这能有所帮助。
https://stackoverflow.com/questions/10083184
复制相似问题