Адресной ячейке нужна переменная высота.
В viewWillAppear
Я рисую тестовую ячейку, чтобы зафиксировать высоту этикетки в иваре.
В методе делегата tableView:heightForRowAtIndexPath
я использую ivar, чтобы установить высоту для фактической ячейки адреса.
Код:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UITableViewCell *testCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"addressCell"] autorelease];
testCell.textLabel.text = @"Address";
testCell.detailTextLabel.text = [selectedPatient valueForKey:@"address"];
testCell.selectionStyle = UITableViewCellSelectionStyleNone;
testCell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
testCell.frame = CGRectMake(0,0,100,30);
[testCell addSubview:testCell.detailTextLabel];
[testCell sizeToFit];
CGSize maxSize;
// HERE is where the problem occurs
// maxSize.width is 35 when it should be 200
maxSize.width = testCell.detailTextLabel.frame.size.width;
//
maxSize.height = 500;
UIFont *font = testCell.detailTextLabel.font;
CGSize testSize = [[selectedPatient valueForKey:@"address"] sizeWithFont:font constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap];
addressLabelHeight = testSize.height;
[testCell removeFromSuperview];
}
Проблема определения ширины тестовой ячейки. Когда NSLog'ing cellForRowAtIndexPath:
показывает ширину, равную 200, но ширина моего testCell составляет всего 35. Это приводит к тому, что высота становится слишком большой, показывая ячейку со слишком большим пробелом.
Я исправил проблему, просто установив maxSize.width = 200
, но мне было любопытно, что я делал неправильно, чтобы динамически получить ширину detailLabel?