我正在使用UICollectionView
在我的應用程序中顯示數據。現在問題是當我滾動視圖時,有時單元格位置不穩定。他們開始重疊在一起。我檢查了我在下面的方法中提供的值。他們是正確的。這裏是我的代碼:UICollectionViewCells重疊
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
,我使用默認的佈局,
self.collectionView.collectionViewLayout = [[UICollectionViewFlowLayout alloc] init];
人覺得我注意到,UICollectionViewCell不是根據UICollectionView寬度 調整[uicollectionView細胞重疊] [2]
!而且您可以在附加圖像中看到,集合視圖背景顏色(紅色)不會位於完整UICollectionViewCell
的背面。需要一些指導。
謝謝。
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
Post *post=[_fetchedResultsController objectAtIndexPath:indexPath];
LoungeUserPostCell *loungepostcell=(LoungeUserPostCell *)cell;
if (indexPath.row==1)
{
loungepostcell.userPostedText.text=post.chat_msg;
[email protected]"";
loungepostcell.lblUsername.text=[NSString stringWithFormat:@"userid =%@", post.user_id];
}
else
{
if (post.chat_img_medium !=nil || post.chat_img_full!=nil)
{
// CGRect chat_msg_rect=CGRectFromString(post.chat_msg_rect);
[loungepostcell willHaveImage:YES imageRect:CGRectMake(10, [post.height floatValue]-kPostImageHeight, kPostImageWidth, kPostImageHeight)];
if (post.chat_img_medium!=nil) {
[loungepostcell.userPostedImage setImageWithURL:[NSURL URLWithString:post.chat_img_medium] placeholderImage:[UIImage imageNamed:@"G-story.png"]];
}
else
[loungepostcell.userPostedImage setImageWithURL:[NSURL URLWithString:post.chat_img_full] placeholderImage:[UIImage imageNamed:@"G-story.png"]];
}
else
{
[loungepostcell willHaveImage:NO imageRect:CGRectZero];
}
loungepostcell.userPostedText.text=post.chat_msg;
loungepostcell.lblPostTime.text=[[[Shared instance]dateFormateForLosAngeles]stringFromDate:post.chat_time];
loungepostcell.lblUsername.text=[NSString stringWithFormat:@"%@", post.user_detail.user_name];
}
return cell;
}
你能顯示你的cellForItemAtIndexPath方法嗎? – rishi
爲cellForItemAtIndexPath增加了代碼 –
我相信這個問題是由於一些流佈局問題 –