我对UITableView和StackMob SDK的最新版本有奇怪的行为。
我正在尝试显示表中的用户列表。我的请求代码类似于StackMob的this tutorial:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"username" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[self.managedObjectContext executeFetchRequest:fetchRequest onSuccess:^(NSArray *results) {
[self.refreshControl endRefreshing];
self.objects = results;
[self.tableView reloadData];
} onFailure:^(NSError *error) {
[self.refreshControl endRefreshing];
NSLog(@"An error %@, %@", error, [error userInfo]);
}];然后在每次调用
- (UITableViewCell *)tableView:cellForRowAtIndexPath:SDK向服务器发送请求
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSManagedObject *object = [self.objects objectAtIndex:indexPath.row];
cell.textLabel.text = [object valueForKey:@"username"];
return cell;
}我找到的其他链接:1,2,3
发布于 2013-06-25 11:15:38
我认为缓慢的原因是每个新单元的创建都必须等待连接到服务器以获取“用户名”。我认为最好的解决方案是更新到2.0 SDK (如果你还没有使用它的话)。并启用缓存,请参阅here了解详细操作方法。这样,初始获取将使用username对象填充缓存,并且每次调用cellForRowAtIndexPath中的NSManagedObject都不会导致网络请求。
https://stackoverflow.com/questions/17278939
复制相似问题