【发布时间】:2012-12-27 14:22:20
【问题描述】:
得到了一堆UIButtons,其中一些需要根据情况改变颜色,目前是这样处理的:
UIButton *button;
button = [self.view viewWithTag:positionInArray];
[button setBackgroundColor:[UIColor cyanColor]];
button = [self.view viewWithTag:positionInArray-1];
[button setBackgroundColor:[UIColor cyanColor]];
button = [self.view viewWithTag:positionInArray+3];
[button setBackgroundColor:[UIColor cyanColor]]
button = [self.view viewWithTag:positionInArray+4];
[button setBackgroundColor:[UIColor cyanColor]];
它可以工作,但是将按钮设置为标签的代码会引发以下警告:
“使用 'UIView *' 类型的表达式初始化 'UIButton *__strong' 的不兼容指针类型”
我该如何正确地做到这一点?
【问题讨论】:
-
您可以转换为 (UIButton *) 但看起来它仍然可以以更好的方式完成。
-
我该怎么做?我以前从来没有涉足过这个,一个不发出警告的解决方案至少比发出警告的解决方案要好,即使它不漂亮。
标签: objective-c ios cocoa-touch uibutton