如何在tableview中维护按钮图像状态

时间:2011-12-27 04:45:59

标签: iphone xcode uitableview

我有一个表格视图,按下按钮后每个单元格都有一个按钮,按钮图像得到改变,但是如果我滚动tableview,那么按钮图像会出现在以前的状态,如何避免这个问题。

2 个答案:

答案 0 :(得分:1)

在数组中存储按钮的状态,并在加载单元格时,检查数组中该单元格的状态并正确设置按钮。

答案 1 :(得分:0)

实际上是它的重装问题。所以我的建议是

cellForRowAtIndexPath

if(cell == nil){
.................
 alloc your button and give him a tag

 [cell.contentview addSubview yourbutton];
.................
}
yourbutton = (uibutton*)[cell.contentview viewwithtag:buttontag];

if(indexPath.row == your expected index && buttonchangedBolean == YES){

yourbutton.backgroundimage = [uiimage imagenamed:@"imagename.png"];
 }

如果您不明白,请毫不犹豫地敲我,这只是对您的建议。如果您发布代码,我可以给您一个解决方案。无论如何尝试我当前的建议可能会对您有所帮助。