0

UITableView と StackMob SDK の最新バージョンで奇妙な動作が発生します。

テーブルにユーザーのリストを表示しようとしています。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]);
}];

そして、各呼び出しの後

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

私が見つけた他のリンク: 123

4

1 に答える 1

0

遅い理由は、新しいセルを作成するたびに、サーバーへの接続を待って「ユーザー名」を取得する必要があるためだと思います。最善の解決策は、2.0 SDK に更新することだと思います (まだ使用していない場合)。キャッシュを有効にする方法の詳細については、こちらを参照してください。そうすれば、最初のフェッチでユーザー名オブジェクトがキャッシュに取り込まれ、cellForRowAtIndexPath で NSManagedObject を呼び出すたびにネットワーク リクエストが発生しなくなります。

于 2013-06-25T03:15:38.490 に答える