objective-c - 克隆或复制 UIViewController 或 UIView

标签 objective-c uiview uiviewcontroller copy clone

UII需要copy,self controller或者self.view,我试过了:

UIView* viewOfSelf =[self.view copy];
UIViewController* controller = [self copy];

UIView* viewOfSelf =[self.view mutableCopy];
UIViewController* controller = [self mutableCopy];

错误是:

    -[UIViewController mutableCopyWithZone:]: unrecognized selector sent to instance 0xb803490
    -[UIView copyWithZone:]: unrecognized selector sent to instance 0x6e0acb0

最佳答案

使用 -

NSData *tempArchiveView = [NSKeyedArchiver archivedDataWithRootObject:self.view];
UIView *viewOfSelf = [NSKeyedUnarchiver unarchiveObjectWithData:tempArchiveView];

同样-

NSData *tempArchiveViewController = [NSKeyedArchiver archivedDataWithRootObject:self];
UIViewController *controller = [NSKeyedUnarchiver unarchiveObjectWithData:tempArchiveViewController];

关于objective-c - 克隆或复制 UIViewController 或 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10614276/

相关文章:

iphone - 如何在 iPhone 应用程序中管理模型和 View ?

ios - 仅在一个 ViewController 中旋转

ios - 来自一个来源的多个 View 和 UITables,如何填充它们?

objective-c - 如何在 NSDictionary 中交换键和值?

ios - 尝试仅将 NSDate 用于时间

iphone - 非移动开发人员可以问到的移动开发人员面试问题

objective-c - 如何在旋转的 UIView 中使用 CGRectContainsPoint()

iphone - 给定图层的对象。如何在 iPhone 中查看图层的 View ?

objective-c - UINavigationController 的 addChildViewController 和 topViewController 之间的相互作用

Swift/UIView 绘制类似转速表的东西