To ignore the isKindOfClass loop for uibuttons in scrollview

I have code that creates, adds and adds tags in a uiview, which itself is in uiscrollview. At some point, I'm trying to change (background color and image) some of the buttons with some tags. The problem is that if I select the first button with a tag of 0, then for loops they fly out to change the image, because either uiscrollview or uiview do not have this method. But I'm trying to target buttons in the view (all are in sync). If I select any other buttons, it works as expected. I could compensate for the tag from 0 to one, but I want to know why my for loop is not working.

for (int i=0; i<[devicesArray count]; i++) {
    NSLog(@"red %i", i);

    for (UIView *subview in [uiv_ButtonsView subviews]) {
        if([subview isKindOfClass:[UIButton class]]) {
            int number = [[devicesArray objectAtIndex:i] intValue];
            subview.alpha=1.0;
            [[subview viewWithTag:number] setBackgroundColor:[UIColor redColor]];
            UIButton *btttn = (UIButton *)[subview viewWithTag:number];
            [btttn setBackgroundImage:nil forState:UIControlStateNormal];
        }
    }
}

Thanks - this is now valid code:

for (int i=0; i<[devicesArray count]; i++) {
    int number = [[devicesArray objectAtIndex:i] intValue];
    [[uiv_Quilt viewWithTag:number] setBackgroundColor:[UIColor redColor]];
    [[uiv_Quilt viewWithTag:number] setBackgroundImage:nil forState:UIControlStateNormal];
}
+3
source share
2
for (UIView *subview in [uiv_ButtonsView subviews]) {

subView uiv_ButtonsView

if([subview isKindOfClass:[UIButton class]]) {

subView UIButton

[[subview viewWithTag:number] setBackgroundColor:[UIColor redColor]]; 

. UIButton 0 - . UIButton, , .

UIButton *btttn = (UIButton *)[subview viewWithTag:number]; 

- , , . subView , .

[btttn setBackgroundImage:nil forState:UIControlStateNormal];

, .

, subView, [uiv_ButtonsView viewWithTag:xx], . 1, 0.

+5

[subview viewWithTag:number] ( , subview, -, ). Array uiv_ButtonsView . , uiv_ButtonsView, [uiv_ButtonsView viewWithTag:number].

+1

All Articles