문제

Can I get the objects created in Interface builder in xcode by program ?

I have set the tag and name of the objects (UIButton). The situation is that I used IBAction for "button pressed" action and I can get the current button which trigger the action, but what if I want to get the previous pressing button and set its image?

any suggestions would help !

도움이 되었습니까?

해결책

if you know the tag you can get the UIButton with something like this:

UIButton *button = [self.view viewWithTag:42];
[button setImage....

If you change the image often I would recommend an IBOutlet which is connected to you button.

If you really need the last button you could store it somewhere, preferable in an ivar.

- (IBAction)buttonAction:(id)sender {
    [lastButton setImage:....];
    [sender doSomething];
    lastButton = sender;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top