これは私に午後の費用がかかるが、私はそれを理解したと思う。私が知る限り、これはUITableViewCellがtextLabelとdetailTextLabelをどのようにレイアウトしているかのバグです。行の高さを設定すると、2つのラベルに同じ高さが割り当てられているように見えます。つまり、detailTextLabelの余裕が増えていても、上記の動作を正確に取得できます。問題を解決するために私がした2つのことがあります。私はそれを修正するためにUITableViewCellをサブクラス化しなければならなかったが、最小限のコード量だった。
まず、各行の高さを正しく計算していることを確認します。このメソッドをテーブルビューのデリゲートに配置します。その後
- (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;
}
、サブクラスのUITableViewCellと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
あなたの字幕テキストがセルの一番下に流れているように見えますが、これは私が見ているものですか?また、これはデバイスやシミュレータだけで発生しますか? – jbrennan
heightForRowAtIndexPathの実装を投稿できますか? –
スクリーンショットでうまく触れる。 –