我有三個API
的我從我的ViewController.m
內拉UITableView
,並將其放入UITableView
。即使一個API失敗,加載視圖控制器
如果其中一個網站未加載,是否還有辦法讓UITableView
加載?
現在,ViewController.m
只是不加載,如果所有3個來源沒有按我的方法加載。
這是我使用的方法:在ViewController.m
的UITableView
- (void)loadOneWithSuccess:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *tNE = [defaults objectForKey:[NSString stringWithFormat:@"tNE%@", bn]];
NSString *path = [NSString stringWithFormat:@"xx/%@/", tNE];
[self.eObjectManager getObjectsAtPath:path parameters:nil success:success failure:failure];
}
- (void)loadMedia {
self.combinedModel = [NSMutableArray array];
// Here's the #1
[self loadOneWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult.array];
// Here's the trick. call API2 here. Doing so will serialize these two requests
[self loadTwoWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult.array];
// Here's the trick. call API3 here. Doing so will serialize these two requests
[self loadThreeWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self.combinedModel addObjectsFromArray:mappingResult.array];
[self sortCombinedModel];
[self.tableView reloadData];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"No?: %@", error);
}];
}
所以如果API1
不加載,API2
和API3
仍然會加載和顯示。
我明白你的意思,謝謝你畫出一幅清晰的圖畫。我不確定在新的'loadOneWithCompletion:'我在哪裏放置'[self.eObjectManager getObjectsAtPath:路徑參數:無成功:失敗:失敗];''我以前有過的部分,或者我該怎麼做把它變成你有'callSomeExternalLibrary'的部分? – Realinstomp 2014-11-21 00:20:32
@Realinstomp - 我一定錯過了你發佈的如何調用外部API。請參閱建議具體更改的編輯。 – danh 2014-11-21 01:18:28
這是有道理的,快速的問題,我會把'[self sortCombinedModel];'和'[self.tableView reloadData];'?我無法弄清楚它的最佳工作點。以前它在'loadMedia'內部的'loadThreeWithSuccess'中。 – Realinstomp 2014-11-21 01:59:30