问题
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