【问题标题】:Issue with UICollectionView reloadDataUICollectionView reloadData 的问题
【发布时间】:2013-12-01 21:08:12
【问题描述】:

我在我的项目中使用UICollectionView。但是我遇到了一些问题:当我调用reloadData 并滚动时,cellForItemAtIndexPath 不起作用。这是我的代码:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return [listImage count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView1 cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"indexpath %d", indexPath.row);
    NSString *cellIdentify = @"HomeCollectionViewCell";

    HomeCollectionViewCell *cell = (HomeCollectionViewCell *)[collectionView1 dequeueReusableCellWithReuseIdentifier:cellIdentify forIndexPath:indexPath];

    NSMutableDictionary *dictionary = [listImage objectAtIndex:indexPath.row];
    //set image pop-up for  first time login
    UIImageView *imageViewSignUp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_popupSignUp.png"]];
    if (indexPath.row == 5 && ![IQUser currentUser]) {
        imageViewSignUp.frame = CGRectMake(120, self.view.frame.size.height-100, 60, 63);
        [self.view addSubview:imageViewSignUp];
    }

    //set data for product or share
    [cell.contentView setUserInteractionEnabled:YES];
        NSString *string = [[dictionary objectForKey:kDetail] objectForKey:kImage];

        if ([string rangeOfString:@"http://"].location != NSNotFound) {
            [self setImageWithString:cell.imageView aURL:string];
        } else {
            cell.imageView.image = [UIImage imageNamed:string];
        }


    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

}

-(CGSize)collectionView:(UICollectionView *)collectionView1 layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = collectionView.frame.size;
    return size;
}

-(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{

}

collectionView 有问题?!

【问题讨论】:

  • 请给出如何调用重载数据和滚动的代码。 [self.collectionView reloadData] 应该始终有效。

标签: ios objective-c image uicollectionview


【解决方案1】:

什么不适用于 UICollectionView ?请说明您的问题。

你为什么要在 cellForItemAtIndexPath 中的 UIView 上设置图像

UIImageView *imageViewSignUp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_popupSignUp.png"]]; if (indexPath.row == 5 && ![IQUser currentUser]) { imageViewSignUp.frame = CGRectMake(120, self.view.frame.size.height-100, 60, 63); [self.view addSubview:imageViewSignUp]; }

【讨论】:

  • 哦,这是我想要显示的不同图像,就像弹出窗口一样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-03
  • 1970-01-01
  • 2018-03-26
相关资源
最近更新 更多