Is subclassing UIWebView frowned upon? [closed]

五迷三道 提交于 2019-12-07 08:44:20

问题


I've heard varying things about whether or not creating a Subclass of UIWebView is allowable. Can someone link me to any documentation that clarifies this one way or another?


回答1:


Under Subclassing Notes of the UIWebView reference, all it says is:

Subclassing Notes

The UIWebView class should not be subclassed.

It doesn't say why. I would guess that it's to maintain the integrity of the underlying WebKit control or something, I dunno.




回答2:


There are mixed messages coming from Apple on this.

The docs do say not to subclass as BoltClock noted. However, one of the presentations from WWDC 2011, Rich Text Editing in Safari on iOS, suggests subclassing. It appears to be the only way to add custom UIMenuItems.

From the slides:

// For your UIWebView subclass:
- (void)bold:(id)sender {
    [self stringByEvaluatingJavaScript:@”document.execCommand(‘Bold’)];
 }
 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(bold:))
    return YES;
    return [super canPerformAction:action withSender:sender];
}

I need functionality other than Copy and Paste in my app so I'll be subclassing.



来源:https://stackoverflow.com/questions/4893135/is-subclassing-uiwebview-frowned-upon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!