cyclingIsBetter
cyclingIsBetter

Reputation: 17591

IOS: manage element in some UIViews

In my app I have 5 UIView in my viewcontroller and each view has inside 6 UILabel. For each label I set a tag in each view, for example:

In first UIView: firtLabel tag 101, secondLabel tag 102 exc... In second UIView: firtLabel tag 101, secondLabel tag 102 exc... In third UIView: firtLabel tag 101, secondLabel tag 102 exc... exc...

and for each UIView I set a tag, for example: for first UIView tag 1 for second UIView tag 2 exc...

then in my code I do:

for (int i = 0; i<5; i++){

    UIView *viewSingle = (UIView*)[self.view viewWithTag:i+1];
    UILabel *data1 = (UILabel*)[viewSingle viewWithTag:100+i+1];
    [[data1 setText:[array1 objectAtIndex:i]];
    UILabel *data2 = (UILabel*)[viewSingle viewWithTag:100+i+2];
    [[data2 setText:[array2 objectAtIndex:i]];

    exc...
} 

this code change only labels in first UIView and not in other UIView, why?

Upvotes: 0

Views: 201

Answers (1)

Marcin Kuptel
Marcin Kuptel

Reputation: 2664

You should not use i when you calculate the tag for retrieving UILabels. For example

UILabel *data1 = (UILabel*)[viewSingle viewWithTag: 101];

instead of

UILabel *data1 = (UILabel*)[viewSingle viewWithTag: 100 + i + 1];

Upvotes: 2

Related Questions