【发布时间】:2013-11-21 04:15:21
【问题描述】:
我在 iOS5 和 iOS6 设备上为 UITextField 和 UITextField 类别提供了类似于以下内容的工作代码。但是,在 iOS7 设备(iPhone5S)上似乎没有调用 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要测试的设备)。
标签: ios objective-c uitextview objective-c-category