Warning generated by UIButton setting code

Posted by Spider-Paddy on Stack Overflow See other posts from Stack Overflow or by Spider-Paddy
Published on 2010-04-23T07:35:46Z Indexed on 2010/04/23 7:43 UTC
Read the original article Hit count: 242

Filed under:
|
|
|
|

I have a for loop setting the background images on buttons, basically the buttons are thumbnail previews of different items & can't be set statically, however the code gives an warning because it runs through all the UIViews but then calls setBackgroundImage which does not apply to all views. The warning is an irritation, I understand what it's complaining about, how can I get rid of it? (I don't want to turn off the warning, I want to fix the problem)

// For loop to set button images  
for (UIView *subview in [self.view subviews])  // Loop through all subviews  
{  
  // Look for the tagged buttons, only the 8 tagged buttons & within array bounds
  if((subview.tag >= 1) && (subview.tag <= 8) && (subview.tag < totalBundles))
  {
    // Retrieve item in array at position matching button tag (array is 0 indexed)
    NSDictionary *bundlesDataItem = [bundlesDataSource objectAtIndex:(subview.tag - 1)];

    // Set button background to thumbnail of current bundle
    NSString *picAddress = [NSString stringWithFormat:@"http://some.thing.com/data/images/%@/%@", [bundlesDataItem objectForKey:@"Nr"], [bundlesDataItem objectForKey:@"Thumb"]];
    NSURL *picURL = [NSURL URLWithString:picAddress];
    NSData *picData = [NSData dataWithContentsOfURL:picURL];
    // Warning is generated here
    [subview setBackgroundImage:[UIImage imageWithData:picData] forState:UIControlStateNormal];
  }
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uibutton