2016-02-10 18 views
8
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ 

    let json = JSON(data: activityTableView.onlineFeedsData)[indexPath.row] // new 
    if(json["topic"]["reply_count"].int > 0){ 
     if let cell: FeedQuestionAnswerTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier_reply) as? FeedQuestionAnswerTableViewCell{ 

      cell.selectionStyle = .None 
      cell.tag = indexPath.row 
      cell.relatedTableView = self.activityTableView 
      cell.configureFeedWithReplyCell(cell, indexPath: indexPath, rect: view.frame,key: "activityTableView") 
      // Make sure the constraints have been added to this cell, since it may have just been created from scratch 
      cell.layer.shouldRasterize = true 
      cell.layer.rasterizationScale = UIScreen.mainScreen().scale 

      return cell 
     } 
    }else{ 
     if let cell: FeedQuestionTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? FeedQuestionTableViewCell{ 

      cell.selectionStyle = .None 
      cell.tag = indexPath.row 
      cell.relatedTableView = self.activityTableView 
      cell.configureFeedCell(cell, indexPath: indexPath, rect: view.frame) 
      // Make sure the constraints have been added to this cell, since it may have just been created from scratch 

      cell.layer.shouldRasterize = true 
      cell.layer.rasterizationScale = UIScreen.mainScreen().scale 
      return cell 
     } 
    } 


    return UITableViewCell() 
} 

esiste una differenza di 200-400 in altezza in ogni cella, quindi provato che attua il calcolo altezza in estimatedHeightForRowAtIndexPath .I sopraelevazione l'altezza esatta stima in questo metodo come bcz di calcoloUITableView problemi di scorrimento sé cella dimensionamento con grande differenza di altezza della cella

e il caching dell'altezza nel metodo willDisplayCell ma continua a scorrere come se ci fosse bisogno di tempo per il rendering.

La cellula è come la carta layout di tipo Facebook con un sacco di dati dinamici con testo di altezza variabile e images.Can qualcuno mi aiuti in questo .grazie

+0

mi puoi dire qualcosa di più su come calcolare l'altezza della cella in 'tableView (_ : estimatedHeightForRowAtIndexPath:) '? –

risposta

0

Se siete in grado di calcolare ogni altezza cellule, basta usare tableView (_: heightForRowAtIndexPath) invece della proprietà estimateRowHeightAtIndexPath. estimateRowHeightAtIndexPath è utilizzato principalmente in smthg come le celle di auto-dimensionamento ecc.

+0

NSMutableDictionary * cellHeightsDictionary; // initialize in code cellHeightsDictionary = @ {}. mutableCopy; –

0

Prova questo. Spero che questo possa aiutarti. Ha funzionato per me. In realtà questo calcola l'altezza della cella prima che venga visualizzata. Grazie.

NSMutableDictionary *cellHeightsDictionary; 

// Inserisci questa in viewDidLoad

cellHeightsDictionary = @{}.mutableCopy; 

Metodi // UITableView delegato

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath 
NS_AVAILABLE_IOS(7_0) 
{ 
    NSNumber *height = [cellHeightsDictionary objectForKey:indexPath]; 
    if (height) return height.doubleValue; 
    return UITableViewAutomaticDimension; 
} 

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [cellHeightsDictionary setObject:@(cell.frame.size.height) forKey:indexPath]; 

} 
+0

thnks @ yogesh proverò sicuramente, ma ho finito per rimuovere l'autolayout e codificarlo nel frame basato sull'utilizzo di AsyncdisplayKit per soddisfare i requisiti ma – Mukesh

+0

ok come desideri. –

Problemi correlati