zoukankan      html  css  js  c++  java
  • NSIndexSet-入门浅析

    NSIndexSet-入门浅析

     
     
    记得上一次,用到,关于删除UITableView分组的方法

    [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationLeft];

     
    确实,搞不懂NSIndexSet是啥东东!
    不懂就看呗!
    在这里,整理了一下常用方法。高手绕道!多多指点!
     
    1.NSIndexSet是什么?
     

    NSIndexSet  是个无符号整数集合。集合中的元素不可变的、不可重复。常被用来当作索引使用。就从它字面上理解,就叫做:索引集合。

     
    2.NSIndexSet的一些常用方法。
     

    类方法:

    创建一个空的索引集合。

    + (id)indexSet

    创建一个索引集合,根据索引值

    + (id)indexSetWithIndex:(NSUInteger)index

    创建一个索引集合,根据一个NSRange对象

    + (id)indexSetWithIndexesInRange:(NSRange)indexRange

    实例方法:

    判断索引集合中是否包含制定的索引值

    - (BOOL)containsIndex:(NSUInteger)index

    判断索引集合是否包含指定的indexSet

    - (BOOL)containsIndexes:(NSIndexSet *)indexSet

    判断索引集合是否包含指定的indexRange

    - (BOOL)containsIndexesInRange:(NSRange)indexRange

    返回索引集合包含的索引数量

    - (NSUInteger)count

    返回indexRange中包含的索引数量

    - (NSUInteger)countOfIndexesInRange:(NSRange)indexRange

    枚举NSIndexSet;执行Block操作,在指定的Rang范围内,并使用指定的options方法。

    - (void)enumerateIndexesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger idx, BOOL *stop))block

    如果,要枚举的NSIndexSet中不存在Rang中所指定的范围,则跳过。

    options参数:

    enum {

       NSEnumerationConcurrent = (1UL << 0),

       NSEnumerationReverse = (1UL << 1),

    };

    typedef NSUInteger NSEnumerationOptions;

    NSEnumerationConcurrent

    枚举过程中,各个Block是同时开始执行的。这样枚举的完成顺序是不确定的。

    NSEnumerationReverse

    以反序方式枚举。

    例子:

     

    // theTwo中是否包含theOne

        BOOL isContains1= [theTwo containsIndexes:theOne];

        BOOL isContains2= [theTwo containsIndex:1];

        BOOL isContains3= [theTwo containsIndex:9];

        // theTwo中是否包含指定的NSMakeRange

        BOOL isContains4= [theTwo containsIndexesInRange:NSMakeRange(0,5)];

        int theCount=[theTwo count];

     

    // 遍历theTwo,在指定的Range范围内,执行Block方法,利用制定的options方式

        // 如果,theTwo中不存在Range中所指定的范围,在theTwo中不存在,则跳过。

        [theTwo enumerateIndexesInRange:NSMakeRange(0,8)

                                options:NSEnumerationReverse

                             usingBlock:^(NSUInteger idx, BOOL *stop) {

            

                                 NSLog(@"-------%d",idx);

                                 NSLog(@"%@",theTwo);

                             }];

    其他的方法,都差不多,就不一一介绍了!

     
    希望对你有所帮助!
  • 相关阅读:
    【矩阵】
    关于集合的思路
    TSQL生成Combguid
    ServiceLocator是反模式
    使用表达式树创建对象
    TeamCity配置笔记
    AutoMapper映射ExpressionTree
    Automapper扩展方法
    Cache&Session Viewer
    Orchard源码:Logging
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/4159787.html
Copyright © 2011-2022 走看看