2

Web サービスからのデータを解析してテーブル ビューに表示するプロジェクトに取り組んでいます。すべて問題ありませんが、tableview のパフォーマンスに満足していません。Web からデータを解析した後、リロード データを呼び出してデータを表示しましたが、セルがすぐに表示されません。10/15 秒後のデータを表示します。データのリロードを呼び出す前に、すべてのデータがロードされていることを確認しました。奇妙なことに、テーブルをドラッグしようとするとすぐにセルが表示されます。

何か案が?

アップデート

-(void)receivedCategories:(NSMutableArray *)categoryItems{
  [self.spinner stopAnimating];
  self.categories=categoryItems;
  if (self.tableView!=nil) {
    [self.tableView reloadData];
  }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return [self.categories count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"CategoryCell";
  CategoryCell    *cell           = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  cell.category                   = [self.categories objectAtIndex:indexPath.row];
  return cell;
}

CategoryCell.m

@implementation CategoryCell

- (void)setCategory:(Category *)category
{
  [self.categoryTitle setText:category.title ];
  [self.categorySubTitle setText:category.description];
}

@end
4

5 に答える 5

24

[self.tableView reloadData];メインスレッドから呼び出していないようで、それが問題の原因である可能性があります。

あなたは試すことができます:

[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];

詳細については、ここで受け入れられた回答も確認してください。

于 2012-10-17T05:10:14.820 に答える
0

表示されているコードの量 (なし) では、非常に多数のレコードで reloadData を呼び出しているため、または時間のかかる解析/計算を行っているため、パフォーマンスが低下していると言わざるを得ません。セルを作成しています。また、これらのセルに画像を表示している場合、パフォーマンスの問題も発生する可能性があります。

于 2012-10-16T14:12:09.543 に答える
-1

CategoryCell を作成するときは? 初めて dequeueReusableCell は nil を返します。次に、カテゴリ セルを作成します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"CategoryCell";
  CategoryCell    *cell           = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (!cell) {
    cell = [[[CategoryCell alloc] init] autorelease];   }

  cell.category                   = [self.categories objectAtIndex:indexPath.row];
  return cell;
}
于 2012-10-16T14:32:26.787 に答える