Category is alternative of subclassing. What will happen if the category message already has been implemented in the class. Take UIViewController as example,
@implementation UIViewController (Landscape)
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
@end
So if we get any XXViewController which extends UIViewController, is that the default message will be implemented like above ?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
As you can see that I aim to make all XXViewController support landscape, so use category to reach this purpose.
Actually the traditional strategy will use subclass, and it works. How about the category way ?
Thanks