0

I have strange behavior with UITableView and StackMob SDK last version.

I'm try to show list of users in the table. My request code like in this tutorial by StackMob:

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]);
}];

and then after each calling of

- (UITableViewCell *)tableView:cellForRowAtIndexPath:

SDK sends request to the server

- (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;
}

Other links I found: 1, 2, 3

Community
  • 1
  • 1
Rost K.
  • 262
  • 2
  • 14

1 Answers1

0

I think the reason for the slowness is that every new cell creation has to wait on a connection to the server to fetch 'username'. I think the best solution is to update to the 2.0 SDK (if you are not already using it). And enable the cache, see here for details of how. That way the initial fetch will populate the cache with the username objects and each call to the NSManagedObject in cellForRowAtIndexPath will then not cause a network request.

combinatorial
  • 9,132
  • 4
  • 40
  • 58