Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

crazyapple777

macrumors newbie
Original poster
May 19, 2010
5
0
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?
 
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?
 
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:

Code:
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?
 
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).
I've tried that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.