howto populate controls when program startup

Discussion in 'Mac Programming' started by DannyDN, Dec 20, 2011.

  1. DannyDN macrumors newbie

    Dec 14, 2011
    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
  2. jiminaus macrumors 65816


    Dec 16, 2010
  3. DannyDN thread starter macrumors newbie

    Dec 14, 2011
    thanks, that cleared out a bit. But how about item 1 to 3, where is the control configured with these values?
  4. mfram, Dec 21, 2011
    Last edited: Dec 21, 2011

    mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    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];

Share This Page