0

我正在使用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; 

}

enter image description here

+0

你能顯示你的cellForItemAtIndexPath方法嗎? – rishi

+0

爲cellForItemAtIndexPath增加了代碼 –

+0

我相信這個問題是由於一些流佈局問題 –

回答

0

我發現這個問題,這個問題是在小區,我加入全視圖作爲一個子視圖,因爲我使用的筆尖。我這樣做是因爲我想使用筆尖和UICollectionViewCell類。

[self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"LoungeUserPostCell" owner:self options:nil]objectAtIndex:0]]; 

- (id)initWithFrame:(CGRect)frame { 

    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
     self.backgroundColor=[UIColor orangeColor]; 

     [self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"LoungeUserPostCell" owner:self options:nil]objectAtIndex:0]]; 

     [self onLoadAdjustments]; 
    } 
    return self; 
} 

我現在註冊爲筆尖在Collection視圖和使用- (void)awakeFromNib方法來使筆尖的變化。

+0

您可以接受答案並關閉問題。 – rishi

+0

2天后我可以接受:) –