【发布时间】:2018-04-10 13:25:06
【问题描述】:
我将 CircularSpinner 加载程序应用于我的 tableview 列表。如果单元格已加载,如何隐藏加载程序?现在每次访问都会显示加载器。
示例代码如下:-
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[CircularSpinner show:@"Loading" animated: TRUE type:CircularSpinnerTypeDeterminate showDismissButton:[NSNumber numberWithBool:TRUE] delegate:self];
[CircularSpinner setValue:0.4 animated: TRUE];
}
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
[CircularSpinner setValue:1.0 animated: TRUE];
}
}
已编辑:-
这是我调用 API 的函数,setUpData 将在 ViewDidLoad 中调用。
-(void)setUpData{
[self.manager GET:@"http://api.XXX.com/api/announcement" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
_serverDataArr = responseObject;
self.dataArr=[NSMutableArray array];
for (NSDictionary *subDic in self.serverDataArr) {
Announcement_Model *model=[[Announcement_Model alloc]initWithDic:subDic];
[self.dataArr addObject:model];
}
_rowArr=[Events_DataHelper getFriendListDataBy:self.dataArr];
_sectionArr=[Events_DataHelper getFriendListSectionBy:[_rowArr mutableCopy]];
[self.tableView reloadData];
} failure:^(NSURLSessionTask *operation, NSError *error) {
// [CircularSpinner setValue:1.0 animated: TRUE];
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Please try again"
message:[error localizedDescription]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleCancel
handler:nil];
[alertVC addAction:okAction];
[self presentViewController:alertVC animated:YES completion:nil];
}];
}
【问题讨论】:
-
您是否在最后一个索引处的 willDisplayCell 方法中调用任何 API 或从本地数据库(延迟加载)获取数据?
-
使用
CircularSpinner.hide() -
嗨 Vinaykrishnan,不。
-
@Test87 你的
tableView(_:cellForRowAt:)里有什么? -
@staticVoidMan,表格单元显示标题标签、日期和描述
标签: ios objective-c uitableview loader