UILabel
2 行の CustomViewCell に問題があります。
最初にCollectionView
. 1 行のみの場合UILabel
は、タイトルが一番上に表示されます。ただし、リストの最後までスクロールして最初に戻ると、すべてUILabels
が2行になり、タイトルが途中で分割されることがあります
前: 素晴らしいタイトル
後:素晴らしい
eタイトル
と関係があると確信していますがreusable Cells
、何が間違っているのかわかりません...
セルの textLabel を次のように設定します。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyItem* a = [self.fetchedResultsController.fetchedObjects objectAtIndex:indexPath.row];
CustomSelectionView *bookCell = [collectionView dequeueReusableCellWithReuseIdentifier:CustomSelectionCell_IDENTIFIER forIndexPath:indexPath];
//CELL CONTAINS an UIImage (Cover) and two UILabels (Author, Title)
//get image from storage
NSString* isbn = a.isbn;
NSString* filePath = [_mamPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", isbn]];
FDIBookCollectionViewCell* __weak weakCell = bookCell;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData* data = [NSData dataWithContentsOfFile:filePath];
UIImage* image = [UIImage imageWithData:data scale:[[UIScreen mainScreen] scale]];
if (!image) {
//... handle
}
if (image && weakCell) {
dispatch_async(dispatch_get_main_queue(), ^{
weakCell.imageView.image = image;
[weakCell.imageView setNeedsDisplay];
});
}
});
//set author and title
bookCell.titelLabel.text = a.titel;
bookCell.titelLabel.numberOfLines = 2; //title label can have two lines
[bookCell.titelLabel sizeToFit];
return bookCell;
}
セル用 InterfaceBuilder:
BookCell.m
@implementation FDIBookCollectionViewCell {}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
//...
- (void)prepareForReuse {
[super prepareForReuse];
self.imageView.image = nil;
}
@end
誰でもアイデアはありますか?