尝试使用 URL 创建请求的连接。NSMutableData 实例 (responseData) 也会被调用。当连接开始接收响应时,在 NSMutableData 实例上调用 setLength:NSUInteger 方法。
-(void)startDataDownloading
{
NSURLRequest *_request = [NSURLRequest requestWithURL:self.url];
if (_request) {
if (!connecton) {
connecton = [NSURLConnection connectionWithRequest:_request delegate:self];
if (connecton) {
responseData = [NSMutableData data];
[connecton start];
}
}
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
}
但不知何故,它会导致崩溃,并在 setLength 调用上发出警告。该错误指出
" -[__NSCFDictionary setLength:]: 无法识别的选择器发送到实例 0x6a8cf70 2012-11-30 18:00:38.948 RSSReader[8997:f803] *由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'-[__NSCFDictionary setLength:] : 无法识别的选择器发送到实例 0x6a8cf70'"
对此的任何提示将不胜感激。
#import <Foundation/Foundation.h>
#import "DataParser.h"
@protocol DataConnectionDelegate <NSObject>
//protocol methods
@end
@interface UCDataConnection : NSObject <ModelParser>
@property (nonatomic, strong) NSURL *url;
@property (nonatomic, strong) NSURLConnection *connecton;
@property (strong, nonatomic) NSMutableData *responseData;
@property (nonatomic, assign) id<DataConnectionDelegate> delegate;
-(void)startDataDownloading;
- (id)initWithUrl:(NSURL *)_url andDelegate:(id<DataConnectionDelegate>)_delegate;
这是头文件的一部分。抱歉,回复晚了。