我知道您必須已經看到此警告並且經常給出解決方案,但我的情況有點特別。
我只收到一個類的警告,但是正確設置了一切(導入,實現,頭文件等)。我在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