【发布时间】:2011-04-13 13:27:03
【问题描述】:
我在编码时遇到了一个问题,那就是。我使用带有循环的自定义按钮在视图中显示了 20 张图像。一段时间后,我正在用新图像更改按钮图像。但是这里发生的事情是旧图像显示在当前图像的后面。
for(currentRow = 0; currentRow < 5; currentRow++)
{
for (currentColumn = 0 ; currentColumn < 4; currentColumn++)
{
if(indexValue<20)
{
printf("\n index value %d",indexValue);
A *aObject = [aList objectAtIndex:indexValue];
MyCustomButton *myButton = [[MyCustomButton alloc] initWithIdValue:aObject.aName];
CGRect imageFrame = CGRectMake(currentColumn * 80+5, currentRow * 80+5, 67, 67);
[myButton setImage:[UIImage imageNamed:aObject.aName] forState:UIControlStateNormal];
[myButton setFrame:imageFrame];
myButton.backgroundColor=[UIColor clearColor];
[myButton addTarget:self action:@selector(aAction:) forControlEvents:UIControlEventTouchUpInside];
[myView addSubview:myButton];
[myButton release];
myButton = nil;
}
}
}
帮我解决这个问题,
谢谢, 马丹·莫汉。
【问题讨论】:
-
如果你粘贴你的代码,我相信我们会很快解决这个问题
-
请贴一些代码,没有它很难说会发生什么。话虽如此,听起来您正在分配新的 UIImageViews 而不是更改旧的图像。
-
编辑问题并添加最初更新 UIButton 图像的循环。
-
我添加了代码,请参考
-
您似乎是在创建新的按钮集,而不是更改现有按钮的图像?
标签: objective-c cocoa-touch uiimage uibutton