为什么我的 UIView 类别会引起警告?
我向 UIView 添加了一个类别来保存一些转换辅助方法。方法都有效;但是,我收到编译器警告:
警告:“UIButton”可能不会响应“-fadeOutWithDuration:”
我的“UIView+Trans.h”文件如下所示:
@interface UIImage (trans)
- (void) fadeOutWithDuration:(CGFloat)duration;
@end
我的“UIView+Trans.m”文件如下所示:
#import <QuartzCore/QuartzCore.h>
#import "UIView+Trans.h"
@implementation UIView (trans)
- (void) fadeOutWithDuration:(CGFloat) duration {
//...
}
@end
我正在调用如下方法: (并且在使用类别方法的每个文件的顶部都有#import“UIView+Trans.h”。)我还尝试将 UIButton* 转换为 UIView*。
[self.myButton fadeOutWithDuration:kFadeOutDuration];
我使用了这个 中的“NSString+Reverse”示例类别示例文章在同一项目中成功运行,并且没有令人讨厌的警告。
I added a category to UIView to hold some transition helper methods. The methods are all working; however, I get compiler warnings:
warning: 'UIButton' may not respond to '-fadeOutWithDuration:'
My "UIView+Trans.h" file looks like this:
@interface UIImage (trans)
- (void) fadeOutWithDuration:(CGFloat)duration;
@end
My "UIView+Trans.m" file looks like this:
#import <QuartzCore/QuartzCore.h>
#import "UIView+Trans.h"
@implementation UIView (trans)
- (void) fadeOutWithDuration:(CGFloat) duration {
//...
}
@end
And I'm calling the method like this: (and have #import "UIView+Trans.h" at the top of each file that uses the category method.) I've also tried casting the UIButton* to a UIView*.
[self.myButton fadeOutWithDuration:kFadeOutDuration];
I've used the "NSString+Reverse" example from this Categories Example article successfully in the same project and without the pesky warnings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在头文件中,您已在
UIImage
而不是UIView
上声明了类别。In your header file, you've declared the category on
UIImage
notUIView
.