के साथ गतिशील ऊंचाई IOS विकास में नया हूं और यह मेरी समस्या है। मैं प्रतिनिधि "heightForRowAtIndexPath" के माध्यम से एक कस्टम सेल की ऊंचाई गतिशील रूप से गणना करने में सक्षम हूं। तो पहले लोड पर, हर चीज पूरी तरह ठीक दिखती है।आईओएस: एक कस्टम यूटेबलव्यूसेल
मेरी समस्या जैसे ही मैं स्क्रॉलिंग शुरू करता हूं, सबकुछ बस गड़बड़ हो जाता है। मुझे लगता है कि "heightForRowAtIndexPath" को स्क्रॉल करते समय प्रति सेल नहीं कहा जाता है जो स्क्रीन पर डिस्प्ले प्राप्त करता है, इसलिए नई सेल ऊंचाई की गणना नहीं की जा सकती है।
तो मैं थोड़ी देर के लिए यहां फंस गया हूं। मैं सोच रहा था कि आप में से कोई मुझे हाथ उधार दे सकता है। पहले ही, आपका बहुत धन्यवाद।
मैं प्रासंगिक फाइलों में कोड पोस्ट करूंगा। इन फ़ाइलों में कस्टम सेल एच और एम फ़ाइल शामिल हैं। और दृश्य नियंत्रक एम फ़ाइल के प्रासंगिक कार्यों।
// ######################################################
// HelpTableViewCell.h
#import <UIKit/UIKit.h>
@interface HelpTableViewCell : UITableViewCell {
IBOutlet UILabel *labelName;
IBOutlet UILabel *labelDescription;
IBOutlet UIView *viewBackground;
}
@property (nonatomic, retain) UILabel *labelName;
@property (nonatomic, retain) UILabel *labelDescription;
@property (nonatomic, retain) UIView *viewBackground;
@end
// ######################################################
// HelpTableViewCell.m
#import "HelpTableViewCell.h"
@implementation HelpTableViewCell
@synthesize labelName;
@synthesize labelDescription;
@synthesize viewBackground;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
self.labelName.lineBreakMode = UILineBreakModeWordWrap;
self.labelName.numberOfLines = 0;
self.labelName.font = [UIFont boldSystemFontOfSize:15];
[self.labelName sizeToFit];
self.labelDescription.lineBreakMode = UILineBreakModeWordWrap;
self.labelDescription.numberOfLines = 0;
self.labelDescription.font = [UIFont fontWithName:@"Arial" size:15];
[self.labelDescription sizeToFit];
[super setSelected:selected animated:animated];
}
- (void) dealloc {
[labelName release], labelName = nil;
[labelDescription release], labelDescription = nil;
[super dealloc];
}
@end
// ######################################################
// in my view controller m file
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"HelpTableViewCell";
HelpTableViewCell *cell = (HelpTableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HelpTableViewCell" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (HelpTableViewCell *) currentObject;
break;
}
}
}
cell.labelName.text = [self.instructionName objectAtIndex:indexPath.row];
cell.labelDescription.text = [self.instructionDescription objectAtIndex:indexPath.row];
return cell;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellText = [self.instructionDescription objectAtIndex:indexPath.row];
UIFont *cellFont = [UIFont fontWithName:@"Arial" size:15];
CGSize constraintSize = CGSizeMake(320.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 25;
}