Question

this is my first question.

I am trying to programmatically change the background image of a UIButton but there is a problem, I can't find the key of the background image. To understand, this is my code:

    [[self.view viewWithTag:69000+i] setValue:[UIImage imageNamed:[NSString stringWithFormat:@"%d-options.png", i+1]] forKey:@"backgroundImage"];

When this is executed, the app crashes. Giving this error:

Thread 1: signal SIGTRAP in main.m
and in the debugger: (lldb)

So, in case I am right and the crash is caused by the incorrect key (backgroundImage), what is the key that refers to background image?

Thank you very much!!

PD: I need this done by self.view viewWithTag......

Était-ce utile?

La solution

And why don't you use this :

   if([[self.view viewWithTag:69000+i] isKindOfClass:[UIButton class]])
    {
        UIButton *currentButton = (UIButton *)[self.view viewWithTag:69000+i];
        [currentButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d-options.png", i+1]] forState:UIControlStateNormal];
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top