尝试将方法插入到 TouchBegan 中时出现错误消息
我正在尝试在 TapDetectingImageView 文件中创建一个新方法,它向我发出警告,指出它无法找到该方法,即使我已在 .h 文件中声明了该方法。
当我构建它时,具体的三个警告都指向 .m 文件中的 @end 行,它们说:“类 'TapDetectingImageView' 的不完整实现;'未找到 '-functionA:' 的方法定义”; “未找到‘-functionB:’的方法定义”
我缺少什么?我是否不允许在像 TapDetectingImageView 这样的协议文件中执行此操作?
在我的 .h 文件中是:
@interface TapDetectingImageView : UIImageView <AVAudioPlayerDelegate> {
id <TapDetectingImageViewDelegate> delegate;
}
@property (nonatomic, assign) id <TapDetectingImageViewDelegate> delegate;
-(void) functionA:(NSString*)aVariable;
-(void) functionB:(NSString*)aVariable;
@end
在我的 .m 文件中是:
-(void)functionA:(NSString*)aVariable {
// do stuff in this function with aVariable
}
-(void)functionB:(NSString*)aVariable {
// do stuff in this function with aVariable
}
I am trying to create a new method within my TapDetectingImageView file and it's giving me a warning that it cannot find the method even though I have it declared in the .h file.
The specific three warnings all point to the @end line in the .m file when I build it and they say: "Incomplete implementation of class 'TapDetectingImageView' ; 'Method definition for '-functionA:' not found" ; "Method definition for '-functionB:' not found"
What am I missing? Am I not allowed to do this in a protocol file like TapDetectingImageView?
In my .h file is:
@interface TapDetectingImageView : UIImageView <AVAudioPlayerDelegate> {
id <TapDetectingImageViewDelegate> delegate;
}
@property (nonatomic, assign) id <TapDetectingImageViewDelegate> delegate;
-(void) functionA:(NSString*)aVariable;
-(void) functionB:(NSString*)aVariable;
@end
In my .m file is:
-(void)functionA:(NSString*)aVariable {
// do stuff in this function with aVariable
}
-(void)functionB:(NSString*)aVariable {
// do stuff in this function with aVariable
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了...我必须在 .m 文件中将它们声明为私有方法才能使它们工作,然后将它们称为
[self methodName:variableIn]
...无论出于何种原因如果我在 .h 文件中声明它们,它们将不起作用。我在导入文件之后和
实现
之前的 .m 文件中这样声明它们:I figured it out... I had to declare them as private methods within the .m file in order for them to work and then call them as
[self methodName:variableIn]
...for whatever reason they wouldn't work if I declared them in the .h file.I declared them like this in the .m file right after the import files and before
implementation
: