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

  • 相关阅读:
    Error C1189: #error: Please use the /MD switch for _AFXDLL builds
    block,inline和inline-block概念和区别(转载)
    jQuery学习--Code Organization Concepts
    Kafka— —副本(均衡负载)
    Kafka实践1--Producer
    漫画HDFS工作原理(转)
    JavaScript学习笔记3
    搭建简单SBT工程实践
    Hive SQL测试
    SparkSql常用语句
  • 原文地址:https://www.cnblogs.com/liuxiaokun/p/5530260.html
Copyright © 2011-2022 走看看