-[NSButton setImage:] fails to set image after setting image to nil
| Originator: | bewebste | ||
| Number: | rdar://20774731 | Date Originated: | 30-Apr-2015 06:35 PM |
| Status: | Open | Resolved: | |
| Product: | OS X | Product Version: | Mac OS X 10.10.3 (14D131) |
| Classification: | UI/Usability | Reproducible: | Always |
Summary:
If using the -[NSButton setImage:] method to modify a button's image, after calling the method once to set an image, then calling it again with a 'nil' argument, any subsequent calls to setImage: do not alter the button's appearance, regardless of the new image being passed in.
Steps to Reproduce:
This can be reproduced using the attached "ButtonTest" project. The project has a single window set up with an NSButton to receive the images, and a series of other buttons used to set new images on the first button. For comparison, a plain NSImageView is placed just below the "target" button, and we set the same image on that as well. The actions for the three buttons that can be clicked looks like this:
- (IBAction)setImage1:(id)sender
{
self.imageButton.image = [NSImage imageNamed:NSImageNameActionTemplate];
self.imageView.image = [NSImage imageNamed:NSImageNameActionTemplate];
}
- (IBAction)setImage2:(id)sender
{
self.imageButton.image = [NSImage imageNamed:NSImageNameAddTemplate];
self.imageView.image = [NSImage imageNamed:NSImageNameAddTemplate];
}
- (IBAction)clearImage:(id)sender
{
self.imageButton.image = nil;
self.imageView.image = nil;
}
To reproduce the behavior;
1. Click the "Set Image 1" button
2. Click the "Clear Image" button
3. Click the "Set Image 1" button again
Expected Results:
An image should appear in the button after the first step, disappear after the second step, then reappear after the third
Actual Results:
After clicking the "Clear Image" button, all subsequent clicks on either "Set Image 1" or "Set Image 2" result in no change in the button's appearance
Regression:
I have tried numerous variations on the button's type and style, but all of them appear to exhibit the same behavior.
Notes:
In trying to debug this, I noticed that after setting an image the first time, the NSButton appears to gain an NSImageView as its subview, with that view presumably actually drawing the image. Setting the image to nil will remove the image from both the button and the image view. However, after setting the image a second time, the button's 'image' property correctly returns the NSImage, but the NSImageViwe's 'image' property still returns nil.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
FYI: It only happens if the button is layer-backed.
Sample project download link
https://dl.dropboxusercontent.com/u/28921795/ButtonTest.zip