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"];

  • 相关阅读:
    预分区
    Flume学习笔记
    1
    在视图中使用时间
    Java 正则表达式的使用
    Reactor模式(反应器模式)
    Control character in cookie value, consider BASE64 encoding your value , java操作cookie遇到中文会报错的解决方案
    关于这周工作中遇到的关于缓存问题的记录
    eclipse import的项目报autowired cannot be resolved to a type的错误
    m2e插件的新下载地址
  • 原文地址:https://www.cnblogs.com/liuxiaokun/p/5530260.html
Copyright © 2011-2022 走看看