Why does this code not work?
-
29-09-2019 - |
Question
So I have the following code to create an NSButton, and put it on the screen. However, when I run this code, nothing happens. What is wrong with this?
NSButton *newbutton = [[NSButton alloc] initWithFrame:NSMakeRect(100, 100, 109, 151)];
[newbutton setImage:[NSImage imageNamed:@"4Diamonds.png"]];
Solution
The button doesn't appear magically by itself. You have to add it to a visible view, e.g. by using -[NSView addSubView:]
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow