2012-04-10 8 views
2

xmlデータを解析した後に、配列infoservicesで満たすカスタムセルを持つUITableViewがあります。各セルに対してUITableViewカスタムセルをリフレッシュするときの遅延

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      [self.cellNib instantiateWithOwner:self options:nil]; 
      cell = tmpCell; 
      self.tmpCell = nil;   
     }  

     infoService *e = [self.infoservices objectAtIndex:indexPath.row]; 

     cell.name = [e infoName]; 

     NSString *infodetails = [e infoDetails]; 

     if (infodetails == nil) { 
      cell.details = @"Loading..."; 
      [self startInfoDownload:e forIndexPath:indexPath]; 

      NSLog(@"Loading..."); 
     } else { 
      cell.details = infodetails; 
      NSLog(@"Show info detail: %@", infodetails); 
     } 
     return cell; 
} 


- (void)infoDidFinishLoading:(NSIndexPath *)indexPath 
{ 
    infoDownloader *infoserv = [imageDownloadsInProgress objectForKey:indexPath]; 
    if (infoserv != nil) 
    { 

     [infoservices replaceObjectAtIndex:[indexPath row] withObject:infoserv.appRecord]; 

     NSIndexPath *a = [NSIndexPath indexPathForRow:indexPath.row inSection:0]; // I wanted to update this cell specifically 
     ApplicationCell *cell = (ApplicationCell *)[self.tableView cellForRowAtIndexPath:a]; 
     cell.details = [[infoservices objectAtIndex:[indexPath row]] infoDetails]; 

     NSLog(@"Updating=%@", [[infoservices objectAtIndex:[indexPath row]] infoDetails]); 
    } 
} 

私は、個々のセルのために

- (void)startDownload 

でオブジェクトinfoDownloaderからXMLデータを取得し、解析するNSURLConnection sendAsynchronousRequestを使用しています。

データがinfoDownloaderから正常に解析デリゲートメソッドされた後は、

- (void)infoDidFinishLoading:(NSIndexPath *)indexPath 

と呼ばれる問題が

- (void)infoDidFinishLoading:(NSIndexPath *)indexPath 

は、各セルを解析した後に呼び出されると、私は

を見ることができる一方で、ということです
NSLog(@"Updating=%@", [[infoservices objectAtIndex:[indexPath row]] infoDetails]); 

デバッガで正しい詳細を使用すると、セルd oesは直ちにリフレッシュされませんが、6〜7秒後にリフレッシュされます。 infoDidFinishLoading後のデバッグ出力がないので、またcellForRowAtIndexPathは、何らかの理由で

- (void)infoDidFinishLoading:(NSIndexPath *)indexPath 

から呼び出されません。また、cellForRowAtIndexPathが再び呼び出されないので、cell.detailsが実際にどのように更新されるのか分かりません。

アップルのLazyTableImagesローディングの例を使ってこの機能をセットアップしようとしましたが、これは成功しましたが、何がうまくいかないのか分かりません。

答えて

0

データがロードされたらreloadRowsAtIndexPathsに電話する必要があります。セルのデータがロードされているが、セルの図面が更新されていない可能性があります。

また、私は[e infoDetails]nilであれば要求が行われますが、セルにデータがロードされる前に、その[self startInfoDownload:e forIndexPath:indexPath]が同じのダウンロード、複数回呼び出されます複数回要求される可能性があるため、あなたのコードは、同じデータを複数回要求することができると信じてデータ。データを要求した行を追跡する必要があります。

この問題を解決する方法についていくつかのアイデアを、このコードをチェックアウト:UIに影響を与えるhttps://github.com/kgn/Spectttator/blob/master/SpectttatorTest-iOS/RootViewController.m#L123

0

すべての変更は、メインスレッドで実行する必要があります。

テーブルのリフレッシュ、セルの詳細の変更、タブロードの再読み込み、行の再マッピング...はUIに影響する変更です。特に

、あなたが使用して、メインスレッドで変更を実行する必要があります。

dispatch_async(dispatch_get_main_queue(), ^{ 
    cell.details = [[infoservices objectAtIndex:[indexPath row]] infoDetails]; 
} 

またはiOS 4の前に:

cell performSelectorOnMainThread:@selector(setDetails:) withObject:[[infoservices objectAtIndex:[indexPath row]] infoDetails]; 
関連する問題