So i have a button in a view i know how to access it but i have no idea how to change picture on that button. Here is what i got:
for(UIView *button in [okvir subviews]){
if([button isKindOfClass:[UIButton class]]){
UIImage *picture=[UIImage imageWithData:slika];
[button setImage:picture forState:UIControlStateNormal];
}
}
However that results in a error:
No visible @interface for 'UIView' declares the selector 'setImage:forState:'
I’m guessing that’s because button is UIView not UIButton, any idea how to do that?
You need to cast your pointer so that the compiler recognizes it as being a
UIButtonand not a genericUIView. This is entirely safe since you are checking the runtime type of your pointed object, so you can be sure it is aUIButton.Use this: