zoukankan      html  css  js  c++  java
  • ios表视图之UITableViewCellAccessoryCheckmark单选、多选状态保存

    表视图界面跳转,单元格选中状态的保存

    多选

    在cellForRow中: 

            UITableViewCell *Cell = [tableView cellForRowAtIndexPath:indexPath];

    Cell.accessoryType = [[NSUserDefault standardUserDefaults]objectForKey:indexPath]?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone; 

    在didselecte这个方法中 

    Cell.accessoryType = UITableViewCellAccessoryCheckmark; 

    下面加一句 

    [[NSUserDefault standardUserDefaults]setObject:[NSNumber numberWithBool:YES] forKey:indexPath];

    单选

    在cellForRow中: 

    NSInteger row = [indexPath row];

        

        NSInteger oldRow = [NSUD integerForKey:@"indexPath.row"];

        

        NSLog(@"选中行业%ld",(long)oldRow);

        

        if (row == oldRow) {

            

            cell.accessoryType = UITableViewCellAccessoryCheckmark;

            

        }else{

            

            cell.accessoryType = UITableViewCellAccessoryNone;

            

        }

    在didselecte这个方法中 

     NSInteger newRow = [indexPath row];

        

        NSInteger oldRow = ([NSUD initWithUser:@"indexPath.row"] !=nil)?[NSUD integerForKey:@"indexPath.row"]:-1;

        

        if (newRow != oldRow) {

            

            UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];

            

            newCell.accessoryType = UITableViewCellAccessoryCheckmark;

            

            UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:_lastPath];

            

            oldCell.accessoryType = UITableViewCellAccessoryNone;

            

            _lastPath = indexPath;

            

        }

        

        [tableView deselectRowAtIndexPath:indexPath animated:YES];

        

        [NSUD setInteger:_lastPath.row forKey:@"indexPath.row"];

  • 相关阅读:
    Neo4j自定义主键策略
    spring cloud Alibaba nacos 整合Neo4j pom 配置
    spring cloud Alibaba nacos 整合Neo4j配置
    若依前端 devtool source-map设置
    基于draw.io的二次开发,文件增加本地以及oss存储
    十多年来从三个容器管理系统中吸取的教训
    java8 CompletableFuture,allOf多实例返回
    CompletableFuture 使用详解
    使用CompletableFuture实现业务服务的异步调用
    [转]uni-app开发踩坑之路之this指向问题
  • 原文地址:https://www.cnblogs.com/liuxiaokun/p/5530260.html
Copyright © 2011-2022 走看看