【发布时间】:2014-03-27 22:07:10
【问题描述】:
我想为我的UIView 子类覆盖setTintColor: 函数。在 iOS 7 中这样做没有问题,因为该功能是从该版本开始引入的。但是,我不知道如何使这个函数向后兼容 iOS 6。下面会崩溃。
- (void)setTintColor:(UIColor *)tintColor
{
if ([super respondsToSelector:@selector(setTintColor:)]) {
// Crashes here with "unrecognized selector" in iOS 6, probably because
// defining setTintColor: makes respondsToSelector: return YES for all
// objects in the hiearchy regardless of whether it is defined at its
// level.
[super setTintColor:tintColor];
}
self.label.textColor = tintColor;
self.dividerLeft.backgroundColor = tintColor;
self.dividerRight.backgroundColor = tintColor;
}
【问题讨论】:
标签: ios objective-c cocoa-touch inheritance overriding