ios - 使用自定义 tableview 滚动时 Tableview 图像变化

标签 ios iphone objective-c uitableview

我有一个 Tableview,我正在使用 customTableview 单元格来显示单元格

在单元格中,我有 5 个按钮(评级按钮),当我单击特定按钮时,按钮的图像必须更改其工作正常但是当我再次滚动 tableview 时,它们正在更改为正常评级按钮,请参见下图为清楚起见

这是在滚动和点击按钮之前的图像

This is the image before scrolling and clicking nothing on button

点击评级按钮后,图像会像这样变化

enter image description here

但是当再次滚动单元格时,它会变成第一张图片

请帮帮我

代码:

- (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/

相关文章:

ios - ios中使用tag动态生成并访问UITextField

ios - 在多个 UIViewcontroller 应用程序中添加广告横幅

objective-c - 比较不同长度的字符串与 compare :options:range: produces wrong result

iOS - 可以播放 RBGA 视频吗?

ios - 在 algolia 中搜索所有出现的字符串

iphone - EXC_BAD_ACCESS 在 Objective C 中泛洪填充时

ios - iOS13更改状态栏背景颜色

ios - 从 Storyboard 中拖动 UI 元素时 Xcode 崩溃

iPhone:自定义 UITableViewCell 具有多个响应点击的区域?

ios - 如何在另一个 pod .podspec 文件中添加私有(private) CocoaPod 作为依赖项?