PDA

View Full Version : howto populate controls when program startup




DannyDN
Dec 20, 2011, 03:53 AM
Hi out there
I am still trying to get my feed under objective-c, it is a hard job as a newbie.

I have made a popup button, when I push the button it is populated with 3 values: item 1, item 2 and item 3. How do I change the list so this will get reflected when the program starts up, and where in the xcode does the button get populated with these initial values - not in the controller thats for sure, I have searched the entire docs associated with the project but cannot seem to finde anywhere in the code where initial values are being put into the controls used in the nib file. Please help?

If I want to run some custom code when the program starts up, arent there any function that is being fired up from where I can run this code? the actions method is only being fired up when a action has taken place from the user? please inform me, this cant be right?

Regards Danny Nielsen



jiminaus
Dec 20, 2011, 05:01 AM
awakeFromNib:

DannyDN
Dec 21, 2011, 01:59 AM
thanks, that cleared out a bit. But how about item 1 to 3, where is the control configured with these values?

mfram
Dec 21, 2011, 10:08 AM
I wrote a Mandelbrot app that uses a popup-button to select one of three compute "modes". My controller contains an awakeFromNib: selector that initializes the button. In this case, "mode_select" is the Outlet for my controller to communicate with the push button. Notice how the logic of initializing the OpenCL code controls whether an item shows up in the button list or not.

- (void) awakeFromNib
{
[mode_select removeAllItems];
[mode_select addItemWithTitle:@"Single"];
[mode_select addItemWithTitle:@"Multi"];

NSData *source = [NSData dataWithContentsOfURL:[[NSBundle mainBundle]
URLForResource:@"opencl_kernel" withExtension:@"cl"]];

const char *bytes = [source bytes];
const int length = [source length];

if (mandel_opencl_init(bytes, length) == EXIT_SUCCESS)
{
[mode_select addItemWithTitle:@"OpenCL"];
}

[mode_select selectItemAtIndex:1];
...