gpt4 book ai didi

iphone - copyWithZone 问题

转载 作者:行者123 更新时间:2023-12-03 20:52:30 24 4
gpt4 key购买 nike

我正在尝试通过执行以下操作来制作 UIViewController 子类的副本:

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 添加到 View Controller ,则必须重写 NSCoding 方法(encodeWithCoder:initWithCoder:) 正确地序列化和反序列化它们。请参阅Archives and Serializations Programming Guide .

顺便说一句,这基本上就是 nib 文件的工作原理。

关于iphone - copyWithZone 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10083184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com