使用自定义tableview滚动时,Tableview图像会出现问题 [英] Tableview images chaging when scrolling using custom tableview
问题描述
我有一个Tableview,我正在使用customTableview单元格来显示单元格
I have a Tableview and i am using the customTableview cell for displaying the cell
当我点击特定按钮时,我有5个按钮(评级按钮)按钮的图像必须改变其工作正常,但当我再次滚动tableview时,正在更改为正常评级按钮,为了清晰起见,请参阅以下图像
in the cell i have 5 buttons (rating buttons) when i click on particular button the image of the button has to changed its working fine but when i am scrolling the tableview again thay are changing to normal rating buttons see the following images for clarity
这是滚动前单击图像并单击按钮上的任何内容
This is the image before scrolling and clicking nothing on button
点击评级按钮后图像会像这样改变
after clicking the on rating buttons the image is changing like this
但是当再次滚动细胞时它会改变为第一张图像
but when scrolling the cells again its changing to first image
请帮帮我
代码:
- (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;
}
推荐答案
你应该保存的状态按钮图像
和你的
you should save the sate of the button images and in your
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
插入代码以保持更新
ex:
insert code to keep them updated for ex:
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
}
这篇关于使用自定义tableview滚动时,Tableview图像会出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!