Note that there are some explanatory texts on larger screens.

plurals
  1. POUICollectionView images not showing
    primarykey
    data
    text
    <p>I have an issue with the images not showing, even though they are loading. I have tried this several different ways and the same result... no images. I do get white rectangles that are the size and color specified in the Storyboard. I get the correct number of rectangles in the popover. The log shows the names and ids correctly.</p> <p>If I call the array directly, I get the same result... white rectangles.</p> <p>My target is iOS7. Running Xcode 5.0.2. Images are coming from a SQL database. This is a live app, which I am updating to full iOS7 and where I am swapping out a custom grid layout for UICollectionView. Using a CollectionViewController, embedded into a NavigationController, which is accessed via a UIButton. As you can see, there is no custom cell. The images are to show in a popover and are then selectable by the user to change the background of the underlying view.</p> <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BckgndCell" forIndexPath:indexPath]; NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row]; NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:@"id"]; int buttonTag = [buttonTagNumber intValue]; NSString *tempImage = [tempDict objectForKey:@"fileName"]; NSLog(@"Filename: %@", tempImage); NSLog(@"ButtonTagNumber: %@", buttonTagNumber); UIImageView *image = [[UIImageView alloc]init]; image.image = [UIImage imageNamed:tempImage]; NSLog(@"Image.image: %@", image.image); // needed for selecting the background in didSelectItemAtIndexPath _bgtag = buttonTag; return cell; } </code></pre> <p>The fix which includes actually naming the BackgroundCell (duh) in the cellForItemAtIndexPath method and creating a small method in the BackgroundCell controller to set the image.</p> <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { BackgroundCell *cell = (BackgroundCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"BckgndCell" forIndexPath:indexPath]; NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row]; NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:@"id"]; int buttonTag = [buttonTagNumber intValue]; NSString *tempImage = [tempDict objectForKey:@"fileName"]; [cell setImage:[UIImage imageNamed:tempImage]]; // needed for selecting the background in didSelectItemAtIndexPath _bgtag = buttonTag; return cell; } </code></pre> <p>The main cell code;</p> <pre><code>- (id)initWithFrame:(CGRect)frame { _backgroundImage = [[UIImageView alloc] initWithFrame:self.contentView.bounds]; [self.contentView addSubview:_backgroundImage]; if (self) { // Initialization code } return self; } -(void)setImage:(UIImage *)image { _backgroundImage.image = image; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload