我在编码时遇到了一个问题,也就是说,我使用带自定义按钮的循环在视图中显示了20幅图像。一段时间后,我正在用新图像更改按钮图像。但是在这里发生的旧图像显示在当前图像的背面。如何删除旧图像的新图像在objective-c
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;
}
}
}
帮我出这一点,
谢谢 马丹·莫汉。
如果你粘贴你的代码,我相信我们会在没有时间修复 – 2011-04-13 13:31:09
请发布一些代码,它很难分辨没有它的情况。话虽如此,这听起来像你正在分配新的UIImageViews,而不是改变旧的图像。 – MCannon 2011-04-13 13:31:27
编辑该问题并添加循环,在其中最初更新UIButton图像。 – 2011-04-13 13:31:36