在不包括标题

时间:2017-07-13 06:20:58

标签: ios objective-c categories

请帮我解释以下情况:

我为UILabel创建了一个新类别:

//UILabel+Test.h
@interface UILabel (Test)

@end

然后,在实现中,我重写drawRect:方法以简单地显示消息:

//UILabel+Test.m
#import "UILabel+Test.h"

@implementation UILabel (Test)

- (void)drawRect:(CGRect)rect {
    NSLog(@"drawRect now");
}

@end

现在,如果没有在项目中的任何地方包含头文件,当我运行它时,我会收到很多消息“drawRect now”。这怎么可能,因为我知道如果我想使用任何类别方法,我必须在我需要的地方包含.h文件(UILabel + Test.h)。

0 个答案:

没有答案