ठीक है, इसने मुझे दोपहर का खर्च किया, लेकिन मुझे लगता है कि मैंने इसे समझ लिया। जहां तक मैं कह सकता हूं, यह एक बग प्रतीत होता है कि UITableViewCell टेक्स्ट लेबल और विवरण टेक्स्टबेल को कैसे बिछा रहा है। जब आप पंक्ति की ऊंचाई निर्धारित करते हैं, तो यह दो लेबलों के बराबर ऊंचाई आवंटित करता है, जिसका अर्थ यह है कि आप वास्तव में जो व्यवहार देख रहे हैं उसे प्राप्त करते हैं, भले ही विवरण टेक्स्टबेल को और अधिक कमरे की आवश्यकता हो। समस्या को ठीक करने के लिए मैंने दो चीजें यहां दी हैं। मुझे इसे ठीक करने के लिए UITableViewCell को उप-वर्ग करना था, लेकिन यह कोड की न्यूनतम मात्रा है।
सबसे पहले, सुनिश्चित करें कि आप प्रत्येक पंक्ति की ऊंचाई की गणना कर रहे हैं। इस विधि को अपने टेबल व्यू प्रतिनिधि में रखें। अपने खुद के साथ फ़ॉन्ट तरीकों बदलें:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellDetailText = [[self itemForIndexPath: indexPath] detailDescription];
NSString *cellText = [[self itemForIndexPath: indexPath] description];
// The width subtracted from the tableView frame depends on:
// 40.0 for detail accessory
// Width of icon image
// Editing width
// I don't think you can count on the cell being properly laid out here, so you've
// got to hard code it based on the state of the table.
CGSize constraintSize = CGSizeMake(tableView.frame.size.width - 40.0 - 50.0, CGFLOAT_MAX);
CGSize labelSize = [cellText sizeWithFont: [self cellTextLabelFont] constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
CGSize detailSize = [cellDetailText sizeWithFont: [self cellDetailTextLabelFont] constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
CGFloat result = MAX(44.0, labelSize.height + detailSize.height + 12.0);
return result;
}
फिर, उपवर्ग UITableViewCell और ओवरराइड layoutSubviews:
#import "UITableViewCellFixed.h"
@implementation UITableViewCellFixed
- (void) layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = CGRectMake(self.textLabel.frame.origin.x,
4.0,
self.textLabel.frame.size.width,
self.textLabel.frame.size.height);
self.detailTextLabel.frame = CGRectMake(self.detailTextLabel.frame.origin.x,
8.0 + self.textLabel.frame.size.height,
self.detailTextLabel.frame.size.width,
self.detailTextLabel.frame.size.height);
}
@end
स्रोत
2009-07-16 19:20:33
ऐसा लगता है कि आपका उपशीर्षक पाठ सेल के नीचे और अगले में बह रहा है, क्या मैं यह देख रहा हूं? साथ ही, यह डिवाइस या सिम्युलेटर पर भी होता है? – jbrennan
क्या आप ऊंचाई के कार्यान्वयन को पोस्ट कर सकते हैं ForRowAtIndexPath? –
स्क्रीनशॉट के साथ अच्छा स्पर्श। –