有几个按钮,点击其中一个,改变这个按钮的图片,其他按钮设置另一个图片。下面的代码哪里出错了?
NSButton *button = (NSButton *)sender;
NSInteger tag = button.tag;
[button setImage:[NSImage imageNamed:@"menuBtnHover.png"]];
for (int i = 5; i <= 8; i++) {
if (tag != i) {
button =[(NSButton *)[self contentView] viewWithTag:i];
[button setImage:[NSImage imageNamed:@"menuBtn.png"]];
}
}
添加测试,<code>按钮=null
NSLog(@"button tag: %ld %d %@", tag,i ,button);