Cocoa: how to get button type when i have "id button" variable
You can not. From the documentation you linked to, here's a bit on setButtontype
:
The available types are among the most common types of buttons that are also available in the Interface Builder. You can customize different behavior using the
NSButtonCell
setHighlightsBy:
and methodssetShowsStateBy:
.Please note that there is no method
-buttonType
. The set method sets various properties of the buttons, which together define the behavior of the type.
If you really need to figure out the type of the custom button, you need to create a table that determines buttonType
based on possible values highlightsBy
and showsStateBy
.
source to share
The API doesn't give you this function directly.
The method that will give you this function is to give each button a tag based on the button type. You can mark with radio buttons 1, checkboxes with 2 and buttons with 3 (or whatever works for you) during creation. Tags can be assigned using Interface Builder or code. Then your code can just check that tag and act accordingly.
// Where you make the button
[someRadioButton setTag:1];
// Where you just have and "id button"
if ([buttonId tag] == 1) {
// Do radio button stuff
}
source to share