views:

33

answers:

1

I have an image in my iPhone Project. It's a PNG and I can set the background in Interface Builder but I want to do this programatically.

NSLog(@"Before %@", myEasterEgg);
uiImageBackground.backgroundColor = [UIColor purpleColor];
myEasterEgg = [myEasterEgg stringByAppendingString:@"5"];
NSLog(@"After %@", myEasterEgg);
if (CFStringCompare((CFStringRef)myEasterEgg, (CFStringRef)@"52235", 1) == 0) {
    myEasterEgg = @"";
    uiImageBackground.backgroundColor = [UIColor clearColor];
    [uiImageBackground setImage:[UIImage imageNamed:@"dock.png"]];
    uiImageBackground.image = image;
}
[myEasterEgg retain];
NSLog(@"After %@", myEasterEgg);

The above is the code in my button. It doesn't display the dock.png file.

UPDATE. I'VE MODIFIED THE CODE SO THE IF STATEMENT WILL ALWAYS EXECUTE AND IT STILL DOESN'T LOAD THE IMAGE. MODIFIED CODE BELOW!

NSLog(@"Before %@", myEasterEgg);
uiImageBackground.backgroundColor = [UIColor purpleColor];
myEasterEgg = [myEasterEgg stringByAppendingString:@"5"];
NSLog(@"After %@", myEasterEgg);
    myEasterEgg = @"";
    uiImageBackground.backgroundColor = [UIColor clearColor];
    [uiImageBackground setImage:[UIImage imageNamed:@"dock.png"]];
    uiImageBackground.image = image;
[myEasterEgg retain];
NSLog(@"After %@", myEasterEgg);
+1  A: 

The code should work. Either (1) the test never passes so the load image is never called or (2) the dock.png file has not been properly added to the project so that it is loaded in the app bundle.

TechZen
The file is there. I clicked and dragged it to the project->resource folder and copied it to target
Cocoa Dev
The test does pass because I've debugged it and I entered the if statement
Cocoa Dev
I would log the image itself and make sure you have a UIImage object and not a nil. If it is nil, then the `dock.png` file is not properly added to the target.
TechZen