iPad と iPhone で iOS 8.1.2 を使用しています。xib から initWithCoder: で作成され、UICollectionView に表示される UICollectionViewCells があります。
[_collectionView registerNib:[UINib nibWithNibName:@"HomeFeedCell" bundle:nil] forCellWithReuseIdentifier:CELL_IDENTIFIER];
テンプレートの xib セルには、デフォルトの属性付きテキストを持つ UILabel が含まれています。セルは、自動レイアウト制約を使用するようにも設定されています。
セルがインスタンス化され、そのデータで更新されると、次のメソッドを呼び出して属性付きテキストを更新します。
- (void)setLabelsForData:(NSDictionary*)dict_data {
NSMutableAttributedString* attributedText_date = [[NSMutableAttributedString alloc] initWithString:[self dateStringForTimestamp:[dict_data objectForKey:@"ts"]]];
NSMutableAttributedString* attributedText_time = [[NSMutableAttributedString alloc] initWithString:[self timeStringForTimestamp:[dict_data objectForKey:@"ts"]]];
UIFont* font_date = [UIFont fontWithName:@"Helvetica-Bold" size:12.0];
UIFont* font_time = [UIFont fontWithName:@"Helvetica" size:12.0];
[attributedText_date addAttribute:NSFontAttributeName value:font_date range:NSMakeRange(0, attributedText_date.length)];
[attributedText_time addAttribute:NSFontAttributeName value:font_time range:NSMakeRange(0, attributedText_time.length)];
dateLabel.attributedText = attributedText_date;
timeLabel.attributedText = attributedText_time;
}
ただし、UICollectionView がモーダルにプッシュされると、ビュー内のセルが最初に表示され、それぞれが UILabel の属性付きテキストを元の xib デフォルト フォームで約 1 秒間表示してから、最終的に正しいデータとフォーマットで更新されます。UICollectionView が表示されると、これらのセルと新しいセルをスクロールしている間、UILables にはこの問題はありません。UICollectionView の出現時に最初に表示されるもののみ。
私が試してみました:
[cell setNeedsDisplay];
[cell setNeedsLayout];
[collectionView invalidateLayout];
メソッドの最後に。スレッドの問題であることを期待して、メソッド全体をメインスレッドに配置しましたが、うまくいきませんでした。
UILabel の更新が遅い原因は何ですか?