2011-11-30 17 views
5

मेरे पास मेरे UITableViewCell की पृष्ठभूमि में सीमा रंग जोड़ने और छाया ड्रॉप करने के लिए निम्न कोड है। मेरी समस्या यह है कि यह कोड तालिका पर एक विशाल अंतराल का कारण बनता है।छाया और सीमाओं के कारण UITableView लगाना

कृपया मुझे बताएं कि मैं कैसे अपना कोड अनुकूलित कर सकता हूं, UITableView की अंतराल को रोक सकता हूं?

if ([cell viewWithTag:012] == nil && comment.isReply == NO) { 
    UIImageView *iv = [[[UIImageView alloc] initWithFrame:frame] autorelease]; 
    [iv setImage:[UIImage imageNamed:@"paper"]]; 
    [iv setTag:012]; 
    [cell insertSubview:iv atIndex:0]; 

    [iv.layer setBorderWidth:1.0]; 
    [iv.layer setBorderColor:[[UIColor whiteColor] CGColor]]; 

    [iv.layer setShadowColor:[[UIColor blackColor] CGColor]]; 
    [iv.layer setShadowOffset:CGSizeMake(0, 1)]; 
    [iv.layer setShadowOpacity:0.75]; 

} 

else if ([cell viewWithTag:012] == nil && comment.isReply == YES) { 

    frame.origin.x += 35; 

    UIImageView *iv = [[[UIImageView alloc] initWithFrame:frame] autorelease]; 
    [iv setImage:[UIImage imageNamed:@"paper"]]; 
    [iv setTag:012]; 
    [cell insertSubview:iv atIndex:0]; 

    UIImage *arrow = [UIImage imageNamed:@"arrow"]; 
    UIImageView *ivs = [[[UIImageView alloc] initWithFrame:CGRectMake(-12, ([cell frame].size.width/2) + ([arrow size].width/2) , arrow.size.width, arrow.size.height)] autorelease]; 
    [cell addSubview:ivs]; 

    [iv.layer setBorderWidth:1.0]; 
    [iv.layer setBorderColor:[[UIColor whiteColor] CGColor]]; 

    [iv.layer setShadowColor:[[UIColor blackColor] CGColor]]; 
    [iv.layer setShadowOffset:CGSizeMake(0, 0)]; 
    [iv.layer setShadowOpacity:0.75]; 

} 
+0

आप छाया कहां जोड़ रहे हैं? मेरा मतलब है कि क्या आप UITableView डेटा स्रोत में ऐसा करते हैं? यदि ऐसा है, तो आपको वास्तव में एक कस्टम UITableViewCell सबक्लास बनाने और वहां कस्टम यूआई करने में देखना चाहिए। –

+0

क्षमा करें, मैंने इसे स्पष्ट नहीं किया है, यह सेलफॉररोएट इंडेक्सपैथ विधि में है। –

उत्तर

1

आप प्रत्येक लोड पर सेल से छेड़छाड़ करने से बचना चाहिए, बजाय आप यूआई जब सेल/आरंभ नहीं हो जाता बनाई समायोजित करना चाहिए।

उदाहरण के लिए, हर बार जब आप एक नया सेल (या एकाधिक) स्क्रॉल करते हैं तो cellForRowAtIndexPath: विधि का उपयोग करके लोड किया जा सकता है, वर्तमान में आप इस विधि में बहुत से दृश्य परिवर्तन कर रहे हैं, लेकिन ऐसे मामले हो सकते हैं जहां इसकी आवश्यकता नहीं है (उदाहरण के लिए नया सेल वही प्रकार है जैसा कि स्क्रीन से स्क्रॉल किया गया है)। इस यूआई संशोधन को उस स्थान पर ले जाएं जहां सेल प्रारंभ किया गया है, जहां डेटा बदल दिया गया है। आप इसे सबक्लास के साथ या बस इस तरह से कर सकते हैं।

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Reuse id 
    static NSString *identifier1 = @"identifer-1"; 
    static NSString *identifier2 = @"identifier-2"; 
    static NSString *regular = @"regular"; 

    UITableViewCell *cell; 

    if (comment.isReply == NO) { 
     cell = [tableView dequeueReusableCellWithIdentifier: identifier1]; 

     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: identifier1] autorelease]; 

      // Do the UI modification here 
     } 
    } else if (comment.isReply == YES) { 
     cell = [tableView dequeueReusableCellWithIdentifier: identifier2]; 

     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: identifier2] autorelease]; 

      // Do the UI modification here 
     } 
    } else { 
     // Regular cell 
     cell = [tableView dequeueReusableCellWithIdentifier: regular]; 

     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: regular] autorelease]; 
     } 
    } 

    // Load the data into the cell 

    return cell; 
} 

आशा है कि आप जहाँ मैं इस के साथ जा रहा हूँ मिलता है, कुंजी यथासंभव कम भारी सामान करते हैं और करते हैं UITableView कैशिंग का ज्यादा प्रभाव है।

20

अन्य अनुकूलन सलाह के अलावा, को CALayer पर निर्दिष्ट करने से छाया चित्र प्रदर्शन में सुधार होगा। आप कुछ इस तरह से छाया के लिए एक मार्ग का निर्धारण कर सकता है ...

iv.layer.shadowPath = [UIBezierPath bezierPathWithRect:iv.bounds].CGPath; 

तुम भी CALayer पर shouldRasterize बिट पर गौर कर सकते हैं। इससे परत को बिटमैप के रूप में पूर्व-प्रस्तुत किया जा सकता है। यदि आप इस मार्ग पर जाते हैं तो अपने डिवाइस से मेल खाने वाले रास्टराइजेशन स्केल को भी सुनिश्चित करना सुनिश्चित करें।

cell.layer.shouldRasterize = YES; 
cell.layer.rasterizationScale = [UIScreen mainScreen].scale; 
+1

इस महान [ब्लॉग पोस्ट] (http://nachbaur.com/blog/fun-shadow-effects-using-custom-calayer-shadowpaths) को देखें, कुछ अलग छाया पैथ के साथ आप –

+1

का उपयोग कर सकते हैं धन्यवाद rasterization पर इस सलाह के लिए बहुत कुछ ! मेरे लिए चाल है;) अब मेरी टेबल देखें इतनी आसानी से स्क्रॉल करें ^^ – polo987

+0

ओएमजी, धन्यवाद! क्षमा करें, मैं केवल एक बार आपको वोट दे सकता हूं। –

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