我有一个 Tableview,我正在使用 customTableview 单元格来显示单元格
在单元格中,我有 5 个按钮(评级按钮),当我单击特定按钮时,按钮的图像必须更改其工作正常但是当我再次滚动 tableview 时,它们正在更改为正常评级按钮,请参见下图为清楚起见
这是在滚动和点击按钮之前的图像
点击评级按钮后,图像会像这样变化
但是当再次滚动单元格时,它会变成第一张图片
请帮帮我
代码:
- (UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
dataCell = (DataCel)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (dataCell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DataCel" owner:self options:nil]; dataCell = [nib objectAtIndex:0];
}
return dataCell;
}
最佳答案
你应该保存按钮图片的状态 在你的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
插入代码以保持更新 例如:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//create your cell here if it was not created
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
[cell.textLabel setFont:[UIFont boldSystemFontOfSize:13]];
[cell.textLabel setTextColor:[UIColor darkGrayColor]];
[cell.detailTextLabel setFont:[UIFont boldSystemFontOfSize:11]];
[cell.detailTextLabel setTextColor:[UIColor lightGrayColor]];
cell.detailTextLabel.numberOfLines = 2;
}
NSArray *array = [imageArray objectAtIndex:[indexPath row]];
if([[array objectAtIndex:3] isEqual:@"rate3"])
{
//set the code for the rating 3
}
else
{
//insert another rate depending on your object
}
关于ios - 使用自定义 tableview 滚动时 Tableview 图像变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20515183/