UICollectionView reloadData问题

时间:2013-11-18 16:15:44

标签: ios objective-c image uicollectionview

我使用UICollectionView作为我的项目。但是我遇到了一些问题:当我呼叫cellForItemAtIndexPath并滚动时,reloadData无效。这是我的代码:

- (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的一个问题?!

1 个答案:

答案 0 :(得分:0)

什么不能与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]; }