[英]iOS first UICollectionViewCell image not loading ONLY after using constraints
沒有約束,我的UICollectionViewCells立即加載,沒有任何問題。 當我在情節提要板中放置約束以使圖像視圖水平且垂直於單元格居中時,第一個圖像單元格不會加載。 我必須滾動幾次,然后回到開始才能顯示第一個圖像單元。 擺脫約束,它可以正常工作。
我以為圖像可能沒有及時加載,但事實並非如此。
我想念什么?
我可以輸入一些代碼,但這是一個非常標准的UICollectionView,在ViewController中帶有自定義單元格。
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSString *imageName = [NSString stringWithFormat:@"%@", [self.urlArray objectAtIndex:indexPath.row]];
[cell setImageName:imageName];
[cell updateCell];
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return self.collectionView.frame.size;
}
編輯:我只是刪除了導航欄,並且前兩個圖像正在導航欄后面加載。 它們以默認原型CollectionViewCell的大小加載。 一旦我滾動並返回它,它就是預期的大小。
當您不添加約束時,IB將自動為您添加約束,這些約束將根據情節提要中的框架為您提供絕對位置和大小。 很有可能您添加的約束沒有按照您認為的那樣做。
添加[cell layoutIfNeeded]; 就在cellforitematindexpath中的返回單元格固定之前
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.