我已經在iOS5和iOS6設備上使用類似於以下類別的UITextField和UITextField的工作代碼。但是,UITextView類別方法似乎未在iOS7設備(iPhone5S)上調用。的代碼是:iOS7設備上的UITextView類別繼承無法按預期工作
@interface UIView (CustomCategory)
-(void) someCategoryMethod;
@end
@implementation UIView (CustomCategory)
-(void) someCategoryMethod {
NSLog(@"UIView category methods appear to work.");
}
@end
@interface UITextField (CustomCategory)
-(void) someCategoryMethod;
@end
@implementation UITextField (CustomCategory)
-(void) someCategoryMethod {
[super someCategoryMethod];
NSLog(@"UITextField category methods appear to work.");
}
@end
@interface UITextView (CustomCategory)
-(void) someCategoryMethod;
@end
@implementation UITextView (CustomCategory)
-(void) someCategoryMethod {
[super someCategoryMethod];
NSLog(@"UITextView category methods appear to work.");
}
@end
void testFunction() {
UITextView* textView = [[[UITextView alloc] init] autorelease];
[textView someCategoryMethod];
UITextField* textField = [[[UITextField alloc] init] autorelease];
[textField someCategoryMethod];
}
在一個iOS5的設備,此(testFunction)打印:
UIView category methods appear to work.
UITextView category methods appear to work.
UIView category methods appear to work.
UITextField category methods appear to work.
然而,iOS7設備上這個打印:
UIView category methods appear to work.
UIView category methods appear to work.
UITextField category methods appear to work.
所以UIView的類中的方法實際上是優先於UITextView類別方法調用的,這似乎與this answer相矛盾。
任何人都可以澄清上述代碼是否應該按預期工作(即在iOS5和iOS6上)?
你的示例代碼不會重現您在iOS7下你的問題列出輸出。它按照預期的方式輸出。 –
@FruityGeek:代碼*絕對*在我使用的iPhone5S上生成聲明的輸出(因此,我認爲它適用於iOS7,因爲我沒有任何其他iOS7設備可以測試)。 –