禁止Cell被选中之后进入高亮状态

xiaoxiao2021-02-28  107

只能自定义,自定义最好的办法就是把tableView中得cell设置为可编辑的,代码如下:

    UITableViewCell *cell;

   if (indexPath.section ==0) {

        cell=[self.batteryAlertTableViewdequeueReusableCellWithIdentifier:@"ItemCell"];

       if (cell ==nil) {

            cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"ItemCell"];

        }

        NSMutableArray *tempobject=[[NSUserDefaultsstandardUserDefaults]objectForKey:@"batteryAlertMulti"];

       for (NSObject *rowin tempobject)

        {

           NSNumber *tempNum = (NSNumber*) row;

           int rownumber = [tempNum intValue];

           NSInteger selectedIndex = rownumber;

           NSIndexPath *selectedIndexPath = [NSIndexPathindexPathForRow:selectedIndex inSection:0];

 [self.batteryAlertTableViewselectRowAtIndexPath:selectedIndexPathanimated:NOscrollPosition:UITableViewScrollPositionNone];

        }

        cell.textLabel.text = [self.dataArrayobjectAtIndex:indexPath.row];

        cell.textLabel.textColor=[UIColorwhiteColor];

        //[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    }

这样当你选中多个cell 的时候 ,这些cell的颜色都会变得高亮,非常的影响用户的体验,最好的解决办法是在设置cell属性时加上如下代码:

    //去除cell在选中时的高亮白色

    cell.selectedBackgroundView=[[UIViewalloc]initWithFrame:cell.frame];

    cell.selectedBackgroundView.backgroundColor=[UIColorclearColor];

    

   return cell;

}

前一段代码可以参考解决IOS复选框的问题,后一段代码解决选中后的背景高亮问题,在处理IOStableView中得复选框这类问题非常的实用!
转载请注明原文地址: https://www.6miu.com/read-74827.html

最新回复(0)