克隆或复制UIViewController或UIView [英] Clone or Copy UIViewController or UIView

查看:659
本文介绍了克隆或复制UIViewController或UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

错误是:

   -  [UIViewController mutableCopyWithZone:]:无法识别的选择器发送到实例0xb803490 
- [UIView copyWithZone:]:无法识别的选择器发送到实例0x6e0acb0
pre>

解决方案

使用 -

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

同样 -

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


UII need copy, self controller or self.view, i have tried:

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

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

The error is:

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

解决方案

Use -

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

Similarly -

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

这篇关于克隆或复制UIViewController或UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆