所以这个问题把我难住了--可能是一些简单的东西,但我一无所知。
我正在定义一个自定义类,其中包含一个接收一条消息(一个整数)的方法。当调用该方法时,编译器拒绝识别我试图随调用一起发送的消息。(“选择器'sendMessage:‘’没有已知的类方法。从调用和定义中删除消息--即从定义中删除:(int)mode
,从调用中删除:1
--可以让它很好地编译(但我当然会失去这个功能)。
我试着将它定义为一个实例方法和一个类方法--两者都不起作用。
非常感谢你们的集体智慧!
自定义类Communications.h:
@interface Communications : NSString
+(NSString*)sendMessage:(int)mode;
@end
Communications.m
#import "Communications.h"
@interface Communications ()
@end
@implementation Communications
+(NSString*)sendMessage:(int)mode {
// Do something important
}
ViewController.h:
#import "Communications.h"
- (void) tapPanic:(UITapGestureRecognizer*)sender;
ViewController.m:
- (void) tapPanic:(UITapGestureRecognizer *)sender {
[Animations animatePanic:self.view type:0];
panicactive = 1;
NSString* tmpResponse = [Communications sendMessage:1];
UILabel* tmpServerResponsePanic = [self.view viewWithTag:10002];
tmpServerResponsePanic.text = tmpResponse;
[[self serverResponsePanic] setNeedsDisplay];
}
发布于 2014-08-01 06:05:42
所以,把它归结为Xcode的怪异。复制/粘贴通信.h和.m的内容到新文件中,并使用新的类定义(Comms),就可以做到这一点。我认为编译器搞混了,并且记住了这个方法的一个旧定义。
https://stackoverflow.com/questions/25050604
复制相似问题