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

, प्रत्येक कोशिका में ऊंचाई में 200-400 के अंतर नहीं है तो यह विधि के रूप में में सटीक अनुमान ऊंचाई नहीं कर सकते estimatedHeightForRowAtIndexPath .मैं में ऊंचाई गणना को लागू करने की कोशिश की गणना के बीसीजेUITableView सेल ऊंचाई के बड़े अंतर के साथ स्वयं आकार सेल स्क्रॉल मुद्दों

और willDisplayCell विधि में ऊंचाई को कैशिंग करना अभी भी स्क्रॉल कूदता है जैसे इसे प्रतिपादन करने में समय लगता है।

सेल चर ऊंचाई पाठ और images.Can कोई मेरी मदद इस धन्यवाद में

+0

तुम मुझे कैसे 'tableView (में सेल की ऊंचाई की गणना करने के बारे में और अधिक बता सकते हैं _ : estimatedHeightForRowAtIndexPath:) '? –

उत्तर

0

आप प्रत्येक कोशिकाओं ऊंचाई गणना करने में सक्षम है, तो बस का उपयोग के साथ गतिशील डेटा के बहुत सारे के साथ फेसबुक कार्ड के प्रकार लेआउट की तरह है अनुमानित RowHeightAtIndexPath संपत्ति के बजाय tableView (_: heightForRowAtIndexPath)। अनुमानित RowHeightAtIndexPath ज्यादातर स्टेथग में उपयोग किया जाता है जैसे स्वयं को कोशिकाओं आदि।

+0

एनएसएमयूटेबल डिक्शनरी * सेलहेइट्स डिक्शनरी; // कोड सेलहेइट्स डिक्शनरी = @ {} में आरंभ करें। mutableCopy; –

0

इसे आजमाएं। मुझे उम्मीद है कि यह आपकी मदद कर सकता है। यह मेरे लिए काम किया है। वास्तव में यह प्रदर्शित होने से पहले सेल ऊंचाई की गणना करता है। धन्यवाद।

NSMutableDictionary *cellHeightsDictionary; 

// viewDidLoad में इस रखो

cellHeightsDictionary = @{}.mutableCopy; 

// UITableView प्रतिनिधि के तरीके

- (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 मैं निश्चित रूप से कोशिश करता हूं, लेकिन मैं ऑटोलायआउट को हटा देता हूं और एएसआईएनसीडीस्प्लेकिट का उपयोग करके फ्रेम में इसे कोड करता हूं ताकि आपकी आवश्यकताओं के अनुसार – Mukesh

+0

ठीक हो सके। –

संबंधित मुद्दे