我创建了 4 个名为 cell1、cell2、cell3 和 cell4 的按钮,我试图在下面的 for 循环中设置背景图像。单元格 1、2 和 4 已成功加载背景图像。我收到了 cell3 的以下消息。所有单元格都创建相同,每个按钮的标签设置为 1、2、3 和 4。
我不知道为什么 cell3(按钮)不加载。我已经查看了有关此主题的类似先前已回答的问题,但我画了一个空白。
这是失败的代码:
for (int i = 1; i <= 4; ++i) {
UIButton *cellIndex = (UIButton *)([self.view viewWithTag:i]);
NSLog(@"==> viewDidLoad cellIndex1 = (%i)", cellIndex.tag);
[cellIndex setBackgroundImage:[UIImage imageNamed:@"L0background.png"] forState:UIControlStateNormal];
}
这是后台加载的结果:
2013-08-30 09:50:07.898 match[863:11f03] ==> viewDidLoad cellIndex1 = (1)
2013-08-30 09:50:07.899 match[863:11f03] ==> viewDidLoad cellIndex1 = (2)
2013-08-30 09:50:07.899 match[863:11f03] ==> viewDidLoad cellIndex1 = (3)
2013-08-30 09:50:07.900 match[863:11f03] -[UIView setBackgroundImage:forState:]: unrecognized selector sent to instance 0x7d68230
2013-08-30 09:50:07.901 match[863:11f03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setBackgroundImage:forState:]: unrecognized selector sent to instance 0x7d68230'
*** First throw call stack:
(0x1912012 0x1695e7e 0x199d4bd 0x1901bbc 0x190194e 0x27bf 0x6bb1c7 0x6bb232 0x60a3d5 0x60a76f 0x60a905 0x613917 0x22f5 0x5d7157 0x5d7747 0x5d894b 0x5e9cb5 0x5eabeb 0x5dc698 0x277ddf9 0x277dad0 0x1887bf5 0x1887962 0x18b8bb6 0x18b7f44 0x18b7e1b 0x5d817a 0x5d9ffc 0x202d 0x1f55 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb)