I have been trying to set a UIImageView background color (see below) in awakeFromNib
[imageView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alp
Are you sure the objects are not nil? NSAssert or NSParameterAssert are your friends:
-(void) awakeFromNib {
NSParameterAssert(imageView);
NSParameterAssert(testLabel);
NSLog(@"awakeFromNib ...");
[imageView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[testLabel setText:@"Pants ..."];
[super awakeFromNib];
}
If the objects are really initialized, try to log their address and make sure that the instances that appear in viewDidLoad are the same as those in awakeFromNib:
- (void) awakeFromNib {
NSLog(@"test label #1: %@", testLabel);
}
- (void) viewDidLoad {
NSLog(@"test label #2: %@", testLabel);
}
If the numbers are the same, you can create a category to set a breakpoint on setBackgroundColor and peek in the stack trace to see what’s going on:
@implementation UIImageView (Patch)
- (void) setBackgroundColor: (UIColor*) whatever {
NSLog(@"Set a breakpoint here.");
}
@end
You can do the same trick using a custom subclass:
@interface PeekingView : UIImageView {}
@end
@implementation PeekingView
- (void) setBackgroundColor: (UIColor*) whatever {
NSLog(@"Set a breakpoint here.");
[super setBackgroundColor:whatever];
}
@end
Now you’ll set your UIViewObject to be of class PeekingView in the Interface Builder and you’ll know when anybody tries to set the background. This should catch the case where somebody overwrites the background changes after you initialize the view in awakeFromNib.
But I presume that the problem will be much more simple, ie. imageView is most probably nil.