Is subclassing UIWebView frowned upon? [closed]

2019-05-09 05:16发布

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?

2条回答
别忘想泡老子
2楼-- · 2019-05-09 05:23

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.

查看更多
做个烂人
3楼-- · 2019-05-09 05:26

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.

查看更多
登录 后发表回答