关于Object-C中的类别:覆盖现有消息
类别是子类的替代。如果已在类中实现类别消息,将会发生什么。以UIViewController为例,
@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
因此,如果我们得到任何扩展UIViewController的XXViewController,那么默认消息是否会像上面那样实现?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
正如您所看到的,我的目标是使所有XXViewController支持格局,因此使用类别来达到此目的。
实际上传统策略将使用子类,并且它可以工作。类别方式怎么样?
谢谢
没有找到相关结果
已邀请:
2 个回复
荤碗
卧沫