Hello all, I created a UITableViewCell subclass called UITableViewMultiLineCell—half the time it works, but at other times it just causes graphical bugs with other and its own table view, and sometimes causes crashes. Here is how I created it:
This is what it's meant to look like: Link
This is what it sometimes looks like: 1 2 3
When it crashes, I don't believe my code is (directly) responsible, according to the debugger.
Does anyone have any ideas on why this is happening, or have created their own successful implementation?
Thanks!
Code:
#import "UITableViewMultiLineCell.h"
@implementation UITableViewMultiLineCell
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
UIFont * font = [UIFont systemFontOfSize:17];
label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 10, frame.size.width - 20, frame.size.height - 20)] autorelease];
label.font = font;
label.numberOfLines = 0;
[[self contentView] addSubview:label];
}
return self;
}
- (CGFloat)heightForCellOfWidth:(CGFloat)width {
label.frame = CGRectMake(10, 10, width - 20, self.bounds.size.height - 20);
[label sizeToFit];
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, width - 20, label.frame.size.height);
return label.frame.size.height + 20.0;
}
- (void)setText:(NSString *)text {
label.text = text;
}
- (NSString *)text {
return label.text;
}
- (void)dealloc {
[super dealloc];
}
@end
This is what it sometimes looks like: 1 2 3
When it crashes, I don't believe my code is (directly) responsible, according to the debugger.
Does anyone have any ideas on why this is happening, or have created their own successful implementation?
Thanks!