在 uitable 视图中重复使用的单元格的附件类型 [英] accessory type repeats for the reused cells in uitable view

查看:20
本文介绍了在 uitable 视图中重复使用的单元格的附件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将复选标记作为附件类型应用于适用视图中的选定项目.但是所有重用的单元格都会出现复选标记.我们怎样才能避免这个问题?代码:

I want to apply checkmark as accessory type to a selected item in a uitable view. but the checkmark appears for all reused cells. How can we avoid this problem? code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if ([[[data objectAtIndex:indexPath.row] ringtone_id] isEqualToString:selId] ) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }

    }

    // Configure the cell...

    cell.textLabel.text = [[[data objectAtIndex:indexPath.row] ringtone_name] stringByDeletingPathExtension];
    return cell;
}

推荐答案

试试这个:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;


    }

    // Configure the cell...

     if ([[[data objectAtIndex:indexPath.row] ringtone_id] isEqualToString:selId] ) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
     } else {
       cell.accessoryType = UITableViewCellAccessoryNone;
     }

    cell.textLabel.text = [[[data objectAtIndex:indexPath.row] ringtone_name] stringByDeletingPathExtension];
    return cell; }

希望对您有所帮助.

这篇关于在 uitable 视图中重复使用的单元格的附件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆