【问题标题】:Not your usual 'Class' may not respond to 'method' warning - iPhone / Objective-C不是你通常的“类”可能不会响应“方法”警告 - iPhone / Objective-C
【发布时间】:2011-05-16 03:29:21
【问题描述】:


我知道您一定已经看到此警告并经常给出解决方案,但我的情况有点特殊。
我只收到一个类的警告,但所有内容(导入、实现、头文件等)都设置正确。我在 XCode 中编写 Objective-C 代码已经有一段时间了,我会为自己说,我已经获得了相当多的 iPhone 编程经验。我完全确定,一切都很好。
看来,XCode 不知何故无法识别我对课程所做的更改。它甚至建议了一些不再属于此类的方法。我在另一台 Mac 上检查了该项目并在那里构建它,一切都很好,根本没有任何警告。
我不想重新安装 XCode 以摆脱这些不应该出现的恼人警告。关于如何告诉 XCode 它必须给自己买些眼镜有什么建议吗? 非常感谢您的帮助 =)

编辑:好的,只是为了没人能说,我疯了或其他什么,这是代码和最后的小解释:

#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

首先,是的,我知道“[delegate didFinishDownload:receivedData];”这一行会发出警告,但这不是我要写的问题。当我按 alt+esc 键查看方法建议时,上述所有内容都在列表中,还有“sendRequest:theURL:”和“sendMail:”,它们早就被删除了。

【问题讨论】:

  • 我不知道为什么,但是今天启动 XCode 后警告已被删除。打败我...问题解决了,我想...

标签: iphone objective-c xcode warnings


【解决方案1】:

您是否绝对确定在您的机器中某处没有此标头的另一个副本,xcode 可能会在找到您的最新副本之前找到它?

【讨论】:

  • 是的,我非常确定。我什至重命名了这个项目。我认为它与SVN存储库有关,但找不到源=/
【解决方案2】:

--从您保存应用程序的文件夹中删除您的构建, --从模拟器或设备中删除。 --清理所​​有目标。 --点击xcode然后清空缓存...

现在您不会看到任何警告。

【讨论】:

  • 我之前多次按此顺序执行所有操作,但似乎没有任何效果。
【解决方案3】:

Xcode(应用程序菜单)--> Empty Caches...

【讨论】:

    【解决方案4】:

    您是否完成了清除所有目标? (它在 Xcode 的 Build 菜单中。)

    【讨论】:

    • @zhar: 包括预编译的头文件?
    • 如果你的意思是清空缓存,是的,甚至是这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    相关资源
    最近更新 更多