我知道您必须已经看到此警告并且经常给出解决方案,但我的情况有点特别。
我只收到一个类的警告,但是正确设置了一切(导入,实现,头文件等)。我在XCode编写Objective-C已经有一段时间了,并且会为我自己说,我已经赢得了iPhone编程的丰富经验。我完全相信,一切都很好。
看来,XCode莫名其妙地没有认识到我对班级所做的改变。它甚至提出了一些不属于这个类的方法。我在另一台Mac上检查了这个项目并在那里建立了它,并且一切都很好,完全没有任何警告。
我不想重新安装XCode来摆脱这些不应该存在的烦人警告。有关如何告诉XCode必须购买眼镜的建议? 帮助非常感谢=)不是您常用的'Class'可能不会响应'method'警告 - iPhone/Objective-C
编辑:好的,就这样,没有人可以说,我是疯了还是什么,这里是代码,并在年底小的解释:
#import <Foundation/Foundation.h>
@interface URLConnection : NSObject {
NSString *theURL;
NSMutableData *receivedData;
id delegate; // delegate needed for handling response
}
@property (nonatomic, retain) NSMutableData *receivedData;
@property (retain) id delegate;
- (NSData*) sendSynchronousRequest:(NSData*)_postData;
- (void) sendRequest:(NSData*)_postData;
- (void)setDelegate:(id)val;
- (id)delegate;
@end
#import "URLConnection.h"
@implementation URLConnection
@synthesize receivedData, delegate;
- (id) init
{
if (self = [super init]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![[defaults stringForKey:@"bankurl"] isEqualToString:@"<Custom URL>"]) {
theURL = [[defaults stringForKey:@"bankurl"] retain];
} else {
theURL = [[defaults stringForKey:@"bankurl_list"] retain];
}
receivedData = [[NSMutableData alloc] init];
}
return self;
}
- (void)setDelegate:(id)val
{
delegate = val;
}
- (id)delegate
{
return delegate;
}
/* send a synchronous request (specified for xml documents) */
- (NSData*) sendSynchronousRequest:(NSData*)_postData
{
NSString *_urlString = theURL;
NSMutableURLRequest *_urlRequest = [[NSMutableURLRequest alloc] init];
[_urlRequest setURL:[NSURL URLWithString:_urlString]];
[_urlRequest setHTTPMethod:@"POST"];
[_urlRequest setValue:@"text/xml"
forHTTPHeaderField:@"Content-Type"];
[_urlRequest setHTTPBody:_postData];
// response
NSHTTPURLResponse *_urlResponse = nil;
NSError *_error = [[NSError alloc] init];
NSData *_responseData = [NSURLConnection sendSynchronousRequest:_urlRequest
returningResponse:&_urlResponse
error:&_error];
[_urlRequest release];
NSString *_result = [[NSString alloc] initWithData:_responseData
encoding:NSUTF8StringEncoding];
NSLog(@"Response code: %d", [_urlResponse statusCode]);
if ([_urlResponse statusCode] >= 200 && [_urlResponse statusCode] < 300) {
NSLog(@"Response: %@", _result);
}
return _responseData;
}
/* send an asynchronous request (specified for xml documents) */
- (void) sendRequest:(NSData*)_postData
{
NSMutableURLRequest *_urlRequest = [[NSMutableURLRequest alloc] init];
[_urlRequest setURL:[NSURL URLWithString:theURL]];
[_urlRequest setHTTPMethod:@"POST"];
[_urlRequest setValue:@"text/xml"
forHTTPHeaderField:@"Content-Type"];
[_urlRequest setHTTPBody:_postData];
[[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self];
[_urlRequest release];
}
/*
* NSURLRequest Delegate
* if a response comes back, clear receivedData to make room for the response data
*/
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
/*
* NSURLRequest Delegate
* if data is received, append the chunk of data to receivedData
*/
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
/*
* NSURLRequest Delegate
* when all response data has been stored, call didFinishDownload() in the class
* which set itself as the delegate
*/
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[delegate didFinishDownload:receivedData];
[connection release];
//[receivedData release];
}
- (void) dealloc
{
[theURL release];
theURL = nil;
[super dealloc];
}
@end
第一所有,是的,我知道该行“[代理didFinishDownload:receivedData];”会发出警告,但这不是我写的问题。当我按Alt + Esc查看方法建议时,以上所有内容都在列表中,而且还包括“sendRequest:theURL:”和“sendMail:”,这些内容很久以前就被移除了。
我不知道为什么,但今天启动XCode后警告已被删除。打我...问题解决了,我认为... – zhar 2010-11-30 12:54:12