我試圖這樣做使我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