views:

151

answers:

1

I tried this code in the view controller, but it didn't work. Why is that?

- (void)viewDidLoad {
 [self setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
    [super viewDidLoad];
}
+5  A: 

You should set background color to the view, not to its controller:

[self.view setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
Vladimir
What does self refer to then? Is self the controller and view a property of the controller?
awakeFromNib
Correct, self - is a pointer to the current object, that is view controller instance and you need to get view via its property
Vladimir
The code example I found from http://forums.macrumors.com/showthread.php?t=564316 shows them leaving out view. In what file will this work?
awakeFromNib
@awakeFromNib, they must be talking about changing background color in custom UIView subclass - in that case 'self' points to a view itself and there's no need to extra reference.
Vladimir