views:

24

answers:

1

The following works without issue:

toolBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"window_bkd.png"]];

However, I have similar statements scattered throughout my code and wanted to clean it up using the following statements, which crash on executing the first statement:

UIColor *bkdColor = [[UIColor alloc] colorWithPatternImage:[UIImage imageNamed:@"window_bkd.png"]];
toolBar.backgroundColor = bkdColor;
[bkdColor release];

Console output from the crash:

[UIPlaceholderColor colorWithPatternImage:]: unrecognized selector sent to instance 0x5203c90

Thanks for your help, I'm sure this is a Homer Simpson "doh!" mistake.

A: 

You accidently placed an alloc call in your second version, so you are calling colorWithPatternImage on an instance, while it is a class method. Doh! :-) This is how it's done correctly:

UIColor *bkdColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"window_bkd.png"]];
Johannes Rudolph
Yep, that's a doh!. Thank you!
粪便猴子