Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView随机不显示单元格_Ios_Objective C_Uicollectionview_Uicollectionviewcell_Uicollectionviewlayout - Fatal编程技术网

Ios UICollectionView随机不显示单元格

Ios UICollectionView随机不显示单元格,ios,objective-c,uicollectionview,uicollectionviewcell,uicollectionviewlayout,Ios,Objective C,Uicollectionview,Uicollectionviewcell,Uicollectionviewlayout,我有一个垂直滚动的UICollectionView。它的第一个单元格包含另一个水平滚动的UICollectionView 在随机情况下,水平UICollectionView会加载单元格,而不会显示它。 所以,我能看到的是两个单元格,一片空白,还有更多的单元格。。 我很难找到原因 代码如下所示: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NS

我有一个垂直滚动的UICollectionView。它的第一个单元格包含另一个水平滚动的UICollectionView

在随机情况下,水平UICollectionView会加载单元格,而不会显示它。 所以,我能看到的是两个单元格,一片空白,还有更多的单元格。。 我很难找到原因

代码如下所示:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (collectionView.tag == 1) {

    if (indexPath.section == 1) {

// do some stuff

} else if (collectionView.tag == 999) { // horizontal collection view

    HorizontalCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell999" forIndexPath:indexPath];

    [self addBorderToCellImageView:cell.imageView];

    [self updateHorizontalCell:cell forIndexPath:indexPath];

    return cell;
}

return [[UICollectionViewCell alloc] init]; // in any case, return a cell.
}
第二部分是:

 // updating cells for collectionView.tag = 999;
- (void)updateHorizontalCell:(HorizontalCell *)cell forIndexPath:(NSIndexPath *)indexPath
{

id obj = self.horizontalProductDataSource[indexPath.row]; // use introspection, and act accordingly.
NSLog(@"section %ld, row %ld", (long)indexPath.section, (long)indexPath.row);

if ([obj isKindOfClass:[Product class]]) {

    Product *wishListProduct = (Product *)obj;

    cell.subtitle.hidden = YES;
    cell.title.text = wishListProduct.name;
    NSLog(@"from product: %@", wishListProduct.name);
    NSLog(@"from cell: %@", cell.title.text);
    cell.price.text = [NSString stringWithFormat:@"%.f %@", wishListProduct.totalPrice, NSLocalizedString(@"Shekel", nil)];

    __weak HorizontalCell *weakCell = cell;

    NSString *imageURL;

    Image *image = [wishListProduct.pictuers lastObject];
    imageURL = image.url;

    [cell.imageView setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:imageURL]]
                          placeholderImage:[UIImage imageNamed:@"Icon.png"] 
                                   success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
                                       weakCell.imageView.image = image;
                                   }
                                   failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
                                       logIt(@"error while bringing photos into cells: %@", error);
                                   }];
}

任何帮助都会很棒

这听起来像是一种竞争条件,当数据源仍然没有可用数据时,UICollectionView试图填充单元格。稍后,当您来回滚动时,单元格将填充当前存在的数据。

您是否尝试将tableview和collectionview混合用于水平和垂直滚动?您的意思是什么@德万吉德赛你可以试试这个例子,我已经做过了。在我的应用程序中,它工作得非常好。我有一个tableview+collectionview。它垂直滚动,每个单元格也水平滚动。谢谢@DevangiDesai,但这不是我的问题。并不是我不能显示任何东西,或者布局有问题。一切都很好。问题是有时我“丢失”了一个手机。。。而且它是一个现有的项目,所以这些改变不可能真正发生