2016-02-10 21 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() 
} 

Istnieje różnica w wysokości 200-400 w każdej komórce, więc próbowali realizacji obliczeń wysokość w estimatedHeightForRowAtIndexPath .I przechyłki dokładnej wysokości kosztorysowej w tej metodzie jako bcz obliczeńUITableView kwestie przewijanie samo komórka zaklejania z dużej różnicy wysokości komórek

i buforowanie wysokości w metodzie willDisplayCell, ale nadal przeskakiwanie przebiega tak, jak jest to czasochłonne renderowanie.

Komórka jest jak Facebooku kart układ typu z dużą ilością dynamicznych danych o zmiennej wysokości tekstu i images.Can ktoś może mi pomóc w tej .Dzięki

+0

Czy możesz mi powiedzieć więcej o tym, jak obliczyć wysokość komórki w 'Tableview (_ : estimatedHeightForRowAtIndexPath:) '? –

Odpowiedz

0

Jeśli jesteś w stanie obliczyć wysokość każdej komórki, wystarczy użyć tableView (_: heightForRowAtIndexPath) zamiast propertyRowHeightAtIndexPath. estimRowHeightAtIndexPath jest najczęściej używany w takich samych komórkach jak selfsizing itp.

+0

NSMutableDictionary * cellHeightsDictionary; // zainicjuj w kodzie cellHeightsDictionary = @ {}. mutableCopy; –

0

Wypróbuj ten. Mam nadzieję, że to może ci pomóc. To działa dla mnie. W rzeczywistości oblicza wysokość komórki przed wyświetleniem. Dzięki.

NSMutableDictionary *cellHeightsDictionary; 

// umieścić to w viewDidLoad

cellHeightsDictionary = @{}.mutableCopy; 

// UITableView delegat Metody

- (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 zdecydowanie spróbuję, ale skończyło się usuwanie autolayout i kodu w ramce opartej AsyncdisplayKit do acheive ma wymagania – Mukesh

+0

ok, jak chcesz. –

Powiązane problemy