美文网首页
NSIndexSet-入门浅析

NSIndexSet-入门浅析

作者: petter102 | 来源:发表于2016-06-24 16:02 被阅读153次
  • 关于删除UITableView分组的方法
    [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationLeft];
  • tableView 刷新分区的方法:

        [tableView reloadSections:[NSIndexSet           indexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationFade];
    

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

1.****NSIndexSet****是什么?

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

2.NSIndexSet的一些常用方法。

类方法:

创建一个空的索引集合。

+ (id)indexSet

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

+ (id)indexSetWithIndex:([NSUInteger](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSUInteger))index

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

  • (id)indexSetWithIndexesInRange:([NSRange](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSRange))indexRange

实例方法:

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

  • (BOOL)containsIndex:([NSUInteger](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSUInteger))index

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

- (BOOL)containsIndexes:(NSIndexSet *)indexSet

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

- (BOOL)containsIndexesInRange:([NSRange](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSRange))indexRange

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

- ([NSUInteger](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSUInteger))count

返回indexRange中包含的索引数量

 - ([NSUInteger](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSUInteger))countOfIndexesInRange:([NSRange](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSRange))indexRange

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

  • (void)enumerateIndexesInRange:([NSRange](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSRange))range options:([NSEnumerationOptions](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSEnumerationOptions))opts usingBlock:(void (^)(NSUInteger idx, BOOL *stop))block
    如果,要枚举的NSIndexSet中不存在Rang中所指定的范围,则跳过。

options参数:

    enum {
       NSEnumerationConcurrent = (1UL << 0),
       NSEnumerationReverse = (1UL << 1),
    };

typedef [NSUInteger](file:///Users/zhangzhen/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/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);
                     }];

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

相关文章

  • NSIndexSet-入门浅析

    关于删除UITableView分组的方法 tableView 刷新分区的方法: [tableView rel...

  • NSIndexSet-入门浅析

    1.NSIndexSet是什么? NSIndexSet 是个无符号整数集合。集合中的元素不可变的、不可重复。常被...

  • “浅析” -> “浅尝”

    之前写了几篇入门的文章,这部分文章都是以 “浅析” 开头,比如:“浅析:myBatis”。但是事实上,这些文档从来...

  • 浅析 CSS 布局与定位

    浅析 CSS 布局与定位 较多内容参考:CSS布局与定位入门 一、左右布局 float + clearfix块级元...

  • Xposed入门浅析

    由于项目要求,最近学习了一个被称为 “Android第一神器” 的东西——Xposed,我们看下百度介绍:Xpo...

  • Cordova入门浅析

    目录结构 查看安卓的项目,只有两个module:app和CordovaLib; 入口 代码的入口,只有一个就是Ma...

  • 语音写作 | 入门浅析

    Q:语音写作就是使用讯飞输入法吧 大脑中要先有一个大致的框架。或者直接开始,意识流 然后剩下的就是刻意练习。主要是...

  • 小程序入门浅析

    从0到1开发小程序 服务器https验证 : 微信有文档模板推送 微信开发角色管理者开发者体验者 数据事件分析 开...

  • netty入门浅析(1)

    笔者所有文章第一时间发布于:hhbbz的个人博客 Netty的简单介绍 Netty 是一个 NIO client-...

  • netty入门浅析(2)

    笔者所有文章第一时间发布于:hhbbz的个人博客 简介 在上一章中我们认识了netty,他有三大优点:并发高,传输...

网友评论

      本文标题:NSIndexSet-入门浅析

      本文链接:https://www.haomeiwen.com/subject/buiodttx.html