Initialization Problem!

Discussion in 'iOS Programming' started by crazyapple777, Aug 25, 2010.

  1. macrumors newbie

    May 19, 2010
    Ok, so I have a basic app working and running great, except I have one issue. I can't get anything to happen directly after loading the view, etc. of a class (such as setting properties, reading files, etc.) So far, my solution to this is have the user press a button which does the things that should happen on startup. But that gets a little annoying... I've tried viewDidLoad and initWithFrame (under the default //Initialization code here) but nothing ever happens. Something only happens when the user presses the button (with the same initialization code, I might add). As it seems such a basic problem, why is this not working?
  2. macrumors 6502a

    May 10, 2009
    Des Moines, WA
    You'll need to provide much more information for anyone be able to provide useful assistance.

    Perhaps a description of what your applications is, does and how it works?
  3. thread starter macrumors newbie

    May 19, 2010
    Well, for example: Say I wanted to generate a random number between 1 and 5 (which I've done using the arc4rand function) and display text in a label based on that number. So the code might look like this:

    int num = [mainDelegate generateRandomNum];
    if (num == 1)
         label.text = @"Option 1 Text";
    if (num == 2)
         label.text = @"Option 2 Text";
    if (num == 3)
         label.text = @"Option 3 Text";
    if (num == 4)
         label.text = @"Option 4 Text";
    if (num == 5)
         label.text = @"Option 5 Text";
    The problem is this all works fine when I have it done within an action of pressing a button. But when I put this kind of thing inside any initialization code, nothing happens. How would I go about having this occur after the view loads or is initialized?
  4. macrumors 68000


    Feb 11, 2010
    Put it in the viewDidLoad or viewDidAppear methods
  5. thread starter macrumors newbie

    May 19, 2010
    I've tried that.
  6. macrumors 604

    Aug 9, 2009
    Post your code.

    We need to see more than just the code that assigns a value to label.text.

Share This Page