View Full Version : Initialization Problem!
Aug 25, 2010, 10:51 PM
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?
Aug 26, 2010, 01:04 AM
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?
Aug 27, 2010, 09:22 PM
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?
Aug 27, 2010, 11:54 PM
Put it in the viewDidLoad or viewDidAppear methods
Aug 28, 2010, 08:05 PM
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.
Aug 28, 2010, 08:23 PM
I've tried that.
Post your code.
We need to see more than just the code that assigns a value to label.text.