【发布时间】:2013-04-04 11:26:40
【问题描述】:
我设法通过将NSURLRequest 加载到新的UIWebView 中来深度复制UIWebView。
我还设法使用 javascript 复制了“scrollTo”位置。
现在我正在考虑复制历史,可能还有很多其他的东西。
是否有记录的方法可以正确执行此操作,或者我快到了?
【问题讨论】:
标签: ios objective-c uiwebview deep-copy
我设法通过将NSURLRequest 加载到新的UIWebView 中来深度复制UIWebView。
我还设法使用 javascript 复制了“scrollTo”位置。
现在我正在考虑复制历史,可能还有很多其他的东西。
是否有记录的方法可以正确执行此操作,或者我快到了?
【问题讨论】:
标签: ios objective-c uiwebview deep-copy
不幸的是,没有直接的方法来实现这一点。
由于UIWebView不符合NSCopying协议,我相信你的方法到目前为止是有效的。
如果您想使其可重用,您可以考虑继承 UIWebView 并在 NSCopying 协议方法的 copyWithZone: 方法中实现您的复制算法。
如果这样做,您随后可以使用标准的copy 方法来深度复制您的对象。
举个例子
@interface UICopyableWebView : UIWebView <NSCopying>
@end
#import "UICopyableWebView.h"
@implementation UICopyableWebView
- (id)copyWithZone:(NSZone *)zone {
id copy = [[[self class] alloc] init];
if (copy) {
// copy the relevant features of the current instance to the copy instance
}
return copy;
}
@end
【讨论】: