Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView with iOS 7 not showing up

I have an app I was building for iOS 6 that I recently upgraded to iOS 7. I have a UIScrollView with a few Custom UIViews. Within those UIViews, I have a single UIImageView in each. For some reason, when I set the UIImageView.image in iOS 6, it shows up fine, but iOS 7 will not show them. Here's the code:

int i = 0;

        for (UIImageView *imageView in myImageViewsOutletCollection)
        {
            imageView.image = nil;
            if (imagesArray.count > i)
                imageView.image = [UIImage imageWithData:[imagesArray objectAtIndex:i]];

            if (imageView.image == nil)
                NSLog(@"signature image with index: %i is nil", i);
                    else
                            NSLog(@"It Worked")

            i++;
        }

My app is logging: @"It Worked", so I know the UIImageView.image isn't nil. What could I be doing wrong?

EDIT:

I tried the UIImageRenderingMode:

UIImage *imageForView = [UIImage imageWithData:[imagesArray objectAtIndex:i]];
imageForView = [imageForView imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

imageView.image = imageForView;

Still didn't work. However, @Max_Power89 said:

as it is written on the apple developer forum : imageWithData bug report

this must be a bug. i hope they fix the problem early.

EDIT 2:

I also added this:

NSData *pngData = UIImagePNGRepresentation(imageView.image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];

NSError *writeError = nil;
[pngData writeToFile:[docs stringByAppendingFormat:@"/image.png"] options:NSDataWritingAtomic error:&writeError];
if(writeError!=nil)
{
    NSLog(@"%@: Error saving image: %@", [self class], [writeError localizedDescription]);
}

The image was saved in app's directory, so I know for certain that the image isn't nil.

like image 980
Cody Winton Avatar asked Sep 21 '13 19:09

Cody Winton


People also ask

How do I install UIImageView?

First you create a UIImage from your image file, then create a UIImageView from that: let imageName = "yourImage. png" let image = UIImage(named: imageName) let imageView = UIImageView(image: image!)

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .


1 Answers

It's a problem/bug with Auto Layout constraints in iOS 7. If you remove the constraints on the UIView, it works no problem. You can set frames programmatically if you need to.

like image 102
Cody Winton Avatar answered Oct 13 '22 10:10

Cody Winton