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

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

问题描述

UII 需要副本、自控制器或 self.view,我已经尝试过:

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];

错误是:

    -[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];

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

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