XCode无法识别自定义方法
|
我有一个名为\“ GREST \”的自定义NSObject类,除此方法外,其他所有方法都起作用。自动完成功能甚至无法识别它,老实说,我不知道为什么。我尝试过更改方法的名称和所有内容。当我调用该方法时,它起作用了,我得到的警告是该类可能不响应该方法。
我在头文件中声明了此方法
- (void)connect:(NSString *)connection_url parameters:(NSString *)parameter_string header:(NSString *)header_type
这是实现
- (void)connect:(NSString *)connection_url parameters:(NSString *)parameter_string header:(NSString *)header_type {
NSData *request_data = [parameter_string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *request_length = [NSString stringWithFormat:@\"%d\", [request_data length]];
response_data = [[NSMutableData alloc] init];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:connection_url]];
[request setHTTPMethod:@\"POST\"];
[request setValue:request_length forHTTPHeaderField:@\"Content-Length\"];
if([header_type isEqualToString:@\"\"] || header_type == nil || header_type == NULL) {
[request setValue:@\"application/x-www-form-urlencoded\" forHTTPHeaderField:@\"Content-Type\"];
} else {
[request setValue:header_type forHTTPHeaderField:@\"Content-Type\"];
}
[request setHTTPBody:request_data];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setTimeoutInterval:10];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
if(!connection) {
[self apicall_failed];
}
[connection release];
}
当我尝试调用此方法时,XCode给我以下警告
\'GREST\' may not respond to \'-connect:parameter_string:header_type:\'
编辑,这里是代码的调用方式:
GREST *api = [[GREST alloc] init];
[api setDelegate:self];
[api connect:@\"http://domain.com\" parameter_string:@\"{\'username\':\'hi\'}\" header_type:@\"application/json\"];
[api release];
一切正常,但我现在正试图摆脱此警告。关于如何执行此操作的任何想法?提前致谢!
没有找到相关结果
已邀请:
2 个回复
蹦吃舷弦
至
区别在于您使用的是方法参数的名称,而不是实际的方法/选择器。调用时将导致运行时异常。 编译器会告诉您尝试使用前者的行,而xcode可能会突出显示该行。
哩翔购
至