为什么我的 UIView 类别会引起警告?

发布于 2024-09-25 10:07:49 字数 863 浏览 2 评论 0原文

我向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光下的微笑 2024-10-02 10:07:49

在头文件中,您已在 UIImage 而不是 UIView 上声明了类别。

In your header file, you've declared the category on UIImage not UIView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文