当重新选择(触摸而不抬起手指)已选择的单元格时,存在有关UITableViewCell的textLabel属性的问题。UITableViewCell在选择/突出显示同一单元格后,textLabel高度会重置
我有一个自定义的contentView被添加到textLabel下面的背景中,该textLabel具有动态高度(包括单元格)和textLabel的背景以及始终相同的高度(50.0f-ish)。
我正在使用beginUpdates和endUpdates方法为选择和帧更改设置动画,以防止textLabel在更新发生后立即在单元中居中;大致保持在背景的相同范围内。选择不同的单元格时,没有任何问题,并且textLabel会保留在应该显示的顶部。
现在的主要问题是当用户再次触摸手指(而不是抬起它)在选定的单元格上时,textLabel会根据单元格的高度更改重新调整。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailView *detailView = // Create detail view
// Add UIImageView from content to cell --------------------
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// Change textLabel colors, fontSize, and shadow properties
// Create CustomContentView *ccView = nil;
// ------
// Remove/Hide any existing CustomContentViews
// --- Code here
// -------
switch (hasImageInCustomView) {
case YES:
image = _imageInCustomView;
image = NO;
if (selectedIndexPath.row != indexPath.row) {
[tableView beginUpdates];
[tableView endUpdates];
}
CGRect frame = cell.textLabel.frame;
frame.size.height = 50.0f;
cell.textLabel.frame = frame;
return;
break;
default:
image = [detailView getImage];
break;
}
// ----
// Calculate height for image and add that to heightForExpandedRow property
// -- Code here...
// ----
[tableView beginUpdates];
[tableView endUpdates];
// Add subview with UIImageView
customContentView = [[CustomContentView alloc] initWithFrame:(CGRect){0, 0, kWidth, dynamicExpandedRow}];
contentView.clipsToBounds = YES;
[cell.contentView addSubview:customContentView];
[cell.contentView sendSubviewToBack:customContentView];
[customContentView setContentImage:image];
CGRect frame = cell.textLabel.frame;
frame.size.height = 50.0f;
cell.textLabel.frame = frame;
}
我使用的是iOS 3.0,所以我不认为didHighlightRowAtIndexPath:将工作,如果有任何委托方法是重置为textLabel框架beginUpdates/endUpdates一直呼吁后,我想知道。
我在登录框的变化和它出现像这样:
之前beginUpdates/endUpdates被称为
<UILabel: 0x4e55500; frame = (10 0; 250 199); text = 'Some Text Goes Here...'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4e55570>>
beginUpdates/endUpdates一直呼吁和手动帧后变更
<UILabel: 0x4e55500; frame = (10 0; 250 50); text = 'Some Text Goes Here...'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4e55570>>
高度显示199前这两种方法被调用,之后是50。 但是,无论强制更改帧,只要选定的单元格被重新选择,textLabel就会在单元格中垂直重新垂直重新打开。
如果有人可以帮助,我将不胜感激。
链接到图片的例子 - >http://i50.tinypic.com/2r6o5k5.jpg
我倾向于继承UITableViewCell的子类并使用基于相关问题的layoutSubviews。 – Bill 2013-03-20 03:58:47
不幸的是,继承UITableViewCell并使用layoutSubviews无法正常工作。当用户重新选择一个选定的单元格时,问题仍然存在,并且将textLabel的尺寸重置为适合单元格的新展开高度,同时垂直居中文本。 – Bill 2013-03-20 04:21:04