我添加了uitableview,在其中我試圖添加自定義的UIButton。它已成功添加此代碼:刷新uitableview的內容
image=[UIButton buttonWithType:UIButtonTypeCustom];
image.frame=CGRectMake(240, 7, 25, 25);
image.tag=101;
image2=[UIButton buttonWithType:UIButtonTypeCustom];
image2.frame=CGRectMake(240, 7, 25, 25);
image2.tag=102;
if ([outputlabel.text isEqualToString:@"Yes"]||[outputlabel.text isEqualToString:@"Yes"]) {
[image setImage:[UIImage imageNamed:@"tick.png"] forState:UIControlStateNormal];
[cell1.contentView addSubview:image];
[cell1.contentView bringSubviewToFront:image];
}
else
{
[image2 setImage:[UIImage imageNamed:@"cross.png"] forState:UIControlStateNormal];
[cell1.contentView addSubview:image2];
[cell1.contentView bringSubviewToFront:image2];
}
它首先運行良好。當表格視圖重新加載時,它與uibutton舊圖像重疊。我無法用新值刷新整個表格。有人知道我在代碼中做錯了什麼。
嘗試使用[cell1.contentView setNeedsDisplay:True]每次你設置圖像來刷新單元格 – Neha