Answer the question
In order to leave comments, you need to log in
UICollectionView with custom UICollectionViewCell?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
AnnouncementCollectionViewCell *cell = (AnnouncementCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewCellIdentifier forIndexPath:indexPath];
NSURL *url = [NSURL fileURLWithPath: fileName isDirectory: NO];
[cell.announcement setDelegate:self];
[cell.announcement loadRequest:[NSURLRequest requestWithURL:url]];
int contentHeight = [[cell.announcement stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] integerValue];
NSLog(@"Content Height %d", contentHeight);
CGRect rect = cell.announcement.frame;
rect.size.height = contentHeight;
cell.announcement.frame = rect;
cell.autoresizesSubviews = YES;
cell.frame = rect;
return cell;
}
When filling the collection with data, the
webView does not have time to load the content yet, when the height of the element begins to be calculated
How to make the content load first and then the height of the element is calculated.
If using dispatch_sync the application crashes when loading the collection
Answer the question
In order to leave comments, you need to log in
Don't touch the height in cellForItemAtIndexPath at all. Only after loading data in UIWebView change the height of this webView. When it does, just call - (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths on the indexPath that this webView matches. This will update the content of the desired cell and ask the delegate for its size.
If you are using UICollectionViewDelegateFlowLayout pass the required dimensions to - (CGSize)collectionView:(UICollectionView *)aCollectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath . This method will be called by itself after calling reloadItemsAtIndexPaths
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question