On adding this control to your view, one will see a field that has a blue arrow to the right. This arrow changes in appearance depending on the initialization option. Regardless the choice made on initialization, clicking on the control causes a list of items to appear, or pop-up, from which the user can make a selection.
There are two initialization options, which are obtained by passing one of two boolean values to the method initWithFrame:(CGRect)pullsDown:(BOOL).
Pop-up Button initialized with "pullsDown:NO" |
Displayed options from a Pop-up Button initialized with "pullsDown:NO" |
Pop-up Button initialized with "pullsDown:YES" |
Displayed options from a Pop-up Button initialized with "pullsDown:YES" |
For each of these selection types, one can extract the items from the list by their index number and assign targets and actions to them so that when a user selects the option, a method of our choosing activates. This can make the pop-up button a useful choice in initializing menu commands if one is apposed to using a menu bar object, or for propagating a sequence of changes to the form or other elements of the application based on the selection.
In the following example, we will create one menu of each, and we will assign actions to three of the selections.
Example
Start a new project, and remove the code that creates the text that reads "Hello World!" from the applicationDidFinishLaunching method.
To the applicationDidFinishLaunching method, add the following:
var button = [[CPPopUpButton alloc] initWithFrame:CGRectMake(20, 200, 200, 20) pullsDown:NO];Elsewhere in the AppController object, add the following methods. If you do not like using the console to log messages, you can change these code lines to "alert()" function calls:
[button addItemWithTitle:@"Selection Option 1"];
[button addItemWithTitle:@"Selection Option 2"];
[button addItemWithTitle:@"Selection Option 3"];
[button sizeToFit];
[contentView addSubview:button];
var testMenuItem = [button itemAtIndex:2];
[testMenuItem setTarget:self];
[testMenuItem setAction:@selector(startListening:)];
var button = [[CPPopUpButton alloc] initWithFrame:CGRectMake(20, 250, 200, 20) pullsDown:YES];
[button addItemWithTitle:@"Choose an action:"];
[button addItemWithTitle:@"Start Listening"];
[button addItemWithTitle:@"Stop Listening"];
var menuItem = [button itemAtIndex:1];
[menuItem setTarget:self];
[menuItem setAction:@selector(startListening:)];
menuItem = [button itemAtIndex:2];
[menuItem setTarget:self];
[menuItem setAction:@selector(stopListening:)];
[button sizeToFit];
[contentView addSubview:button];
-(void) option3:(id)senderLoad the page, and you will have an opportunity to play with the various methods and choices. As you change the option selection on each box, if you select the modified options, you will see messages that indicate each "action" was handled appropriately.
{
console.log("Option 3 selected");
}
-(void) startListening:(id)sender
{
console.log("Start Listening");
}
-(void) stopListening:(id)sender
{
console.log("Stop Listening");
}
A list of all the available methods can be found at the API Documentation Page.
That is not a combo box... in fact, a combo box would be a combination of this type of popup and a textbox.
ReplyDeleteIt proved to be Very helpful to me and I am sure to all the commentators here! migliore carabina pcp alta potenza
ReplyDelete