我在我的表格视图中应用了这段代码。但是,我意识到第一次请求的数据加载速度很慢。之后,如果我访问同一页面,记录将加载得更快。任何想法改进第一次加载?谢谢你的帮助。
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://api.domainname.com/api/abc" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
_serverDataArr = responseObject;
self.dataArr=[NSMutableArray array];
for (NSDictionary *subDic in self.serverDataArr) {
Friend_Model *model=[[Friend_Model alloc]initWithDic:subDic];
[self.dataArr addObject:model];
}
_rowArr=[Friend_DataHelper getFriendListDataBy:self.dataArr];
_sectionArr=[Friend_DataHelper getFriendListSectionBy:[_rowArr mutableCopy]];
[self.tableView reloadData];
} failure:^(NSURLSessionTask *operation, NSError *error) {
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Error Retrieving Ninjas"
message:[error localizedDescription]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleCancel
handler:nil];
[alertVC addAction:okAction];
[self presentViewController:alertVC animated:YES completion:nil];
}];
这是我的 cellForRowAtIndexPath 代码:-
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIde=@"cellIde";
Friend_TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIde];
if (cell==nil) {
cell=[[Friend_TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIde];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
if (tableView==_searchDisplayController.searchResultsTableView){
NSString *url_Img_FULL = [_searchResultArr[indexPath.row] valueForKey:@"image"];
[cell.headImageView setImageWithURL:[NSURL URLWithString:url_Img_FULL] placeholderImage:[UIImage imageNamed:@"Placeholder.png"]];
[cell.nameLabel setText:[_searchResultArr[indexPath.row] valueForKey:@"name"]];
}else{
Friend_Model *model=_rowArr[indexPath.section][indexPath.row];
[cell.headImageView setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@"Placeholder.png"]];
[cell.nameLabel setText:model.name];
}
return cell;
}