2016-05-14 10 views
0

Im den folgenden Code unter Verwendung von Bildern von URL zu laden in der SammelansichtUILabel ist nicht sichtbar in Kollektion

-

(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *identifier = @"Cell"; 

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 



    UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100]; 
    UILabel *recipeLabel = (UILabel *)[cell viewWithTag:200]; 


    if ([ImageArray count] >0){ 
    for(int i = 0; i < [ImageArray count]; i++) 
    { 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) { 
      NSData *data0 = [NSData dataWithContentsOfURL: [NSURL URLWithString:[ImageArray objectAtIndex:indexPath.row]]]; 
      UIImage *image = [UIImage imageWithData: data0]; 

      dispatch_sync(dispatch_get_main_queue(), ^(void) { 
       recipeImageView.image = image; 
      }); 
     }); 
    } 
    }else{ 
     UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, cell.bounds.size.width, 40)]; 
     title.text = @"No image record found"; 
     title.tag = 200; 
     [title setHidden:true]; 
     [cell.contentView addSubview:title]; 
    } 

    [spinnerShow stopAnimating]; 

    cell.layer.shouldRasterize = YES; 
    cell.layer.rasterizationScale = [UIScreen mainScreen].scale; 

    return cell; 
} 

Wenn der ImageArray eine URL bekommen hat, wenn Schleife ausgeführt wird. Andernfalls wird die else-Schleife ausgeführt, in der eine Beschriftung angezeigt wird, die besagt, dass kein Bildeintrag gefunden wurde. Aber der Uilabel wird nicht sichtbar

+0

Das Label ist nicht sichtbar, weil Sie es mit '[title setHidden: true];' verstecken. – rmaddy

+0

immer noch nicht sichtbar, auch nach dem Entfernen – Roger

Antwort

0

Warum verwenden Sie für die Schleife in CellForItemAtIndexPath? Diese Methode wird für jedes Element in UICollectionView aufgerufen. In der else-Bedingung fügen Sie ein Protokoll oder einen Haltepunkt hinzu und prüfen, ob es dort hingeht oder immer eingeht, falls Bedingung. Stellen Sie sicher, ob Sie nach der Anzahl der Arrays suchen müssen oder ob das Bild in der URL vorhanden ist.