views:

36

answers:

1

Hola tengo este problema declare esto

IBOutlet UILabel *h1;
IBOutlet UILabel *h2;
IBOutlet UILabel *h3;
IBOutlet UILabel *h4;

y quiero llenar los label con numeros random asi:

for (int i=1; i<=4; i++) {
    int numerosr = random()%12;
    h[i].text = [[NSString alloc]initWithFormat:@"%2.1f", numerosr];
}

pero marca error en h[1] que no reconoce h


Hi I have this problem declare that

IBOutlet UILabel * h1;
IBOutlet UILabel * h2;
IBOutlet UILabel * h3;
IBOutlet UILabel * h4;

and I want to fill the label with random numbers like this:

for (int i = 1; i <= 4; i + +) {
    int numerosr = random ()% 12;
    h [i]. text = [[NSString alloc] initWithFormat: @ "% 2.1f", numerosr]
}

but it makes error in h [1] which does not recognize h

(Thanks to http://translate.google.com/)

+3  A: 

Note that arrays in C start at the 0th index, e.g. h[0]. Also, you don't mention actually populating the array h with your label instances, so I can assume that the members of the array aren't valid. In fact, it's not clear that the array exists at all. You can't assume that because you have a variable h1, you have a variable h[1]: these are entirely independent in C. And therefore in Objective-C, too.

Graham Lee
the array is not declared only iboutlet
Mayoo
@Mayoo: Therefore you cannot access your outlets as if they lived in an array.
BoltClock