我希望此方法检查条件是否为真,然后设置特定按钮(按钮)以获得我指定的图像.这是代码.
-(void)canAfford:(float) f: (UIButton*)button { if([self playerHas:(f)] == YES) { [button setImage:[UIImage imageNamed:nil] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"ButtonBGclicked.png"] forState:UIControlStateHighlighted]; } else { [button setImage:[UIImage imageNamed:@"ButtonBG.png"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:nil] forState:UIControlStateHighlighted]; } }
这是我得到的错误.
2013-09-22 10:35:39.985 Tapple[15663:a0b] CUICatalog: Invalid asset name supplied:,or invalid scale factor: 1.000000
解决方法
你正在调用[UIImage imageNamed:@“”]或[UIImage imageNamed:nil].没有图像与空字符串匹配.如果您要清除图像,请传递nil而不是调用imageNamed:.
试试这个(更新的原始代码,包含@Kyle Fang的评论):
- (void)canAfford:(float) f: (UIButton*)button { if([self playerHas:(f)] == YES) { [button setImage:nil forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"ButtonBGclicked.png"] forState:UIControlStateHighlighted]; } else { [button setImage:[UIImage imageNamed:@"ButtonBG.png"] forState:UIControlStateNormal]; [button setImage:nil forState:UIControlStateHighlighted]; } }