我试图这样做使我UIViewController子类的副本:copyWithZone问题
BookViewController *bookVC = [catalogFlatViewController copy];
,我有以下错误:
'-[BookViewController copyWithZone:]: unrecognized selector sent to instance 0x8e5f00'
我试图这样做使我UIViewController子类的副本:copyWithZone问题
BookViewController *bookVC = [catalogFlatViewController copy];
,我有以下错误:
'-[BookViewController copyWithZone:]: unrecognized selector sent to instance 0x8e5f00'
UIViewController
不符合NSCopying
。如果你想制作一个副本,你必须使用NSCoding
:
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:controller];
UIViewController *newController = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
如果你已经添加了新的ivars到您的视图控制器,你就必须重写NSCoding
方法(encodeWithCoder:
和initWithCoder:
)序列化和反序列化这些正确。见Archives and Serializations Programming Guide。
顺便说一句,这基本上是一个nib文件的工作原理。
参见@Caleb答案在下面的职位:
iOS copyWithZone unrecognized selector only when using device
迦勒的回答是下
UIViewController doesn't implement the NSCopying protocol. Unless you've implemented NSCopying in your own UIViewController subclass, your view controller won't respond to
-copyWithZone:
.
欲了解更多信息:你可能想参考UIViewController class reference 。
但我建议你不要执行NSCopying协议参考,如@RobNapier已在Implementing NSCopying (or NSCopyObject() considered harmful)
希望这有助于给出的非常好,内容丰富的文章之一。
[iOS copyWithZone无法识别的选择器只有当使用设备]的可能重复(http://stackoverflow.com/questions/8539522/ios-copywithzone-unrecognized-selector-only-when-using-device) – 2012-04-10 07:18:05