我是AFNetworking的新手,所以在使用NSURLConnection之前我从未遇到过这个问题
我在添加类别
的帖子请求后使用此方法-(void)getCategories{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString * url = [NSString stringWithFormat:@"%@v2/api/tags",kURL];
NSDictionary *parameters =[self parameterBuild];
[manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
categories = [[NSMutableArray alloc]init];
categories = [responseObject objectForKey:@"tags"];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
问题是.. responseObject总是在一段时间内获取旧数据,就像它的缓存一样......
任何帮助将不胜感激
答案 0 :(得分:0)
问题来了,因为您没有清理数据并在出错时重新加载视图。
-(void)getCategories{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString * url = [NSString stringWithFormat:@"%@v2/api/tags",kURL];
NSDictionary *parameters =[self parameterBuild];
[manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
categories = [[responseObject objectForKey:@"tags"] mutableCopy];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
categories = [NSMutableArray new];
// Reload view here, like you do for success
}];
}