Ios 在一个表视图中按日期排序的1个API源和1个RSS源
这在以前对我非常有效: 但是现在,我的第二个来源是RSS而不是API 我假设我需要以某种方式更改Ios 在一个表视图中按日期排序的1个API源和1个RSS源,ios,arrays,uitableview,rss,restkit,Ios,Arrays,Uitableview,Rss,Restkit,这在以前对我非常有效: 但是现在,我的第二个来源是RSS而不是API 我假设我需要以某种方式更改loadtwithsuccess,但我不知道如何更改 然后,我肯定需要根据第二个源的新日期更新sortCombinedModel 你能帮我吗?谢谢 两个异步调用: - (void)loadOneWithSuccess:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
loadtwithsuccess
,但我不知道如何更改
然后,我肯定需要根据第二个源的新日期更新sortCombinedModel
你能帮我吗?谢谢
两个异步调用:
- (void)loadOneWithSuccess:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure {
NSString *apikey = @kCLIENTKEY;
NSDictionary *queryParams = @{@"apikey" : apikey};
NSString *path = [NSString stringWithFormat:@"v1/n/?limit=4&leafs=%@&themes=%@", leafAbbreviation, themeID];
[self.eObjectManager getObjectsAtPath:path parameters:queryParams success:success failure:failure];
}
- (void)loadTwoWithSuccess:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure {
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:@"http://se.com/rss/c-b/"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
NSLog(@"Success 2: %@", success);
}
作为单一组合模型的负荷源:
- (void)loadMedia {
self.combinedModel = [NSMutableArray array];
[self loadOneWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult];
// here's the trick. call API2 here. Doing so will serialize these two requests
[self loadTwoWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult];
[self sortCombinedModel];
[self.tableView reloadData];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
}
- (void)sortCombinedModel {
[self.combinedModel sortUsingComparator:^NSComparisonResult(id a, id b) {
NSDate *dateA, *dateB;
dateA = ([a isKindOfClass:[Feed self]])? ((Feed *)a).published : ((Data *)a).created_time;
dateB = ([b isKindOfClass:[Feed self]])? ((Feed *)b).published : ((Data *)b).created_time;
return [dateA compare:dateB];
}];
}
排序组合模型:
- (void)loadMedia {
self.combinedModel = [NSMutableArray array];
[self loadOneWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult];
// here's the trick. call API2 here. Doing so will serialize these two requests
[self loadTwoWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult];
[self sortCombinedModel];
[self.tableView reloadData];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
}
- (void)sortCombinedModel {
[self.combinedModel sortUsingComparator:^NSComparisonResult(id a, id b) {
NSDate *dateA, *dateB;
dateA = ([a isKindOfClass:[Feed self]])? ((Feed *)a).published : ((Data *)a).created_time;
dateB = ([b isKindOfClass:[Feed self]])? ((Feed *)b).published : ((Data *)b).created_time;
return [dateA compare:dateB];
}];
}
新表视图:
id model = self.combinedModel[indexPath.row];
if ([model isKindOfClass:[Feed self]) {
Feed *feed = (Feed *)model;
// configure cell with feed
} else {
Data *data = (Data *)model;
// configure cell with data
}
我将尝试在
loadTwoWithSuccess
中为RSS提要使用RestKit,因为这似乎更有意义-