I've created code, so: when the view did load, show up a random image. I've written some code, but it always starts with the same image (and viewbgcolor)..
my code:
-(void)viewDidLoad
{
index = [NSNumber numberWithInt:(([index intValue] + 1) % 6)];
switch ([index intValue]) {
case 0:
moodImage.image = [UIImage imageNamed:@"angry.png"];
self.view.backgroundColor = [UIColor redColor];
break;
case 1:
moodImage.image = [UIImage imageNamed:@"Disappointed.png"];
self.view.backgroundColor = [UIColor brownColor];
break;
case 2:
moodImage.image = [UIImage imageNamed:@"glad.png"];
self.view.backgroundColor = [UIColor orangeColor];
break;
case 3:
moodImage.image = [UIImage imageNamed:@"happy.png"];
self.view.backgroundColor = [UIColor yellowColor];
break;
case 4:
moodImage.image = [UIImage imageNamed:@"sad.png"];
self.view.backgroundColor = [UIColor grayColor];
break;
case 5:
moodImage.image = [UIImage imageNamed:@"surprised.png"];
self.view.backgroundColor = [UIColor greenColor];
break;
}
}
This is really frustrating.. It works well with an IBAction, but not with the viewdidload... Has someone a alternative block of code to let this work?