【问题标题】:Is there a better way to deep copy a UIWebView?有没有更好的方法来深度复制 UIWebView?
【发布时间】:2013-04-04 11:26:40
【问题描述】:

我设法通过将NSURLRequest 加载到新的UIWebView 中来深度复制UIWebView。 我还设法使用 javascript 复制了“scrollTo”位置。 现在我正在考虑复制历史,可能还有很多其他的东西。

是否有记录的方法可以正确执行此操作,或者我快到了?

【问题讨论】:

    标签: ios objective-c uiwebview deep-copy


    【解决方案1】:

    不幸的是,没有直接的方法来实现这一点。

    由于UIWebView不符合NSCopying协议,我相信你的方法到目前为止是有效的。

    如果您想使其可重用,您可以考虑继承 UIWebView 并在 NSCopying 协议方法的 copyWithZone: 方法中实现您的复制算法。

    如果这样做,您随后可以使用标准的copy 方法来深度复制您的对象。

    举个例子

    UICopyableWebView.h

    @interface UICopyableWebView : UIWebView <NSCopying>
    @end
    

    UICopyableWebView.m

    #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  
    

    【讨论】:

      猜你喜欢
      • 2017-11-03
      • 1970-01-01
      • 2019-12-08
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 2018-10-11
      • 2011-03-28
      • 2019-11-05
      相关资源
      最近更新 更多