Cóż, ten kosztował mnie popołudnie, ale myślę, że to wymyśliłem. O ile mogę powiedzieć, wydaje się, że jest to błąd w sposobie, w jaki UITableViewCell układa textLabel i detailTextLabel. Kiedy ustawiasz wysokość wiersza, wydaje się, że przydzielasz równą wysokość dwóm etykietom, co oznacza, że otrzymujesz dokładnie to, co widzisz powyżej, nawet jeśli detailTextLabel potrzebuje więcej miejsca. Oto dwie rzeczy, które zrobiłem, aby rozwiązać problem. Musiałem podklasować UITableViewCell, aby to naprawić, ale jest to minimalna ilość kodu.
Najpierw upewnij się, że obliczasz wysokość każdego rzędu. Umieść tę metodę w delegacie widoku tabeli. Zastąpić metody czcionki z własną rękę:
- (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;
}
Następnie podklasy UITableViewCell i zastąpić 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
Wygląda na to, że tekst napisów przepływa nad dnem komórki, a w następnej jest to, co widzę? Czy dzieje się to również na urządzeniu lub po prostu na symulatorze? – jbrennan
Czy możesz opublikować swoją implementację heightForRowAtIndexPath? –
Miły dotyk ze zrzutem ekranu. –