Mike2012
Mike2012

Reputation: 7725

Programmatically Removing a Button from a Window in Cocoa OSX

I need to programmatically remove a button from a window in Cocoa but the only method close to this was dealloc in NSObject, but this is not what I want to do. Is there a way to actually delete the button from the window not just deallocate its memory?

Upvotes: 1

Views: 537

Answers (2)

Jasarien
Jasarien

Reputation: 58458

An NSButton is a subclass of NSControl, which itself is a subclass of NSView.

You should be able to remove the button from it's superview by calling -removeFromSuperView on the button instance.

Upvotes: 4

Ciarán Walsh
Ciarán Walsh

Reputation: 1866

Send the removeFromSuperview message to the button instance.

Though perhaps you just want to hide it instead (using setHidden:)?

Upvotes: 10

Related Questions