- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在我的单元测试中,我查看了一些边界条件,但我的测试一直失败。当它的索引一直延伸到 NSNotFound-1(每个文档的最大合法值)时,我追踪到它通过索引集进行枚举。
使用这个测试代码:
// Create an index set with NSNotFound-5, NSNotFound-4, NSNotFound-3,
// NSNotFound-2 and NSNotFound-1
NSIndexSet *testSet = [NSIndexSet indexSetWithIndexesInRange:
NSMakeRange( NSNotFound - 5, 5 )];
NSLog( @"Index set with %lu entries: %@", (unsigned long) testSet.count, testSet );
NSLog( @"NSNotFound is %lu and NSNotFound-1 is %lu", NSNotFound, NSNotFound - 1 );
__block int count = 0;
[testSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
NSLog( @"- %lu", (unsigned long) idx );
++count;
}];
NSLog( @"The count is %d", count );
在日志输出中我得到:
Index set with 5 entries: <NSIndexSet: 0x10057f890>[number of indexes: 5 (in 1 ranges), indexes: (9223372036854775802-9223372036854775806)]
NSNotFound is 9223372036854775807 and NSNotFound-1 is 9223372036854775806
- 9223372036854775802
- 9223372036854775803
- 9223372036854775804
- 9223372036854775805
The count is 4
我在我的 Mac 和 iOS 模拟器上试过这个并得到相同的结果(除了 NSNotFound 的实际值,取决于 32 位或 64 位)。
这让我觉得也许我读错了文档。我做错了什么或者这是 Apple 的错误吗?
最佳答案
这不是错误。您设置的值超出了有效值。 “NSIndexSet 类表示唯一无符号整数的不可变集合,因其使用方式而称为索引。此集合称为索引集。索引必须在 0 .. NSNotFound - 1 范围内。”这是 link !
关于ios - 这是 NSIndexSet enumerateIndexesUsingBlock 中的错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23712904/
你能快速枚举一个NSIndexSet吗?如果没有,枚举集合中项目的最佳方法是什么? 最佳答案 在 OS X 10.6+ 和 iOS SDK 4.0+ 中,您可以使用 -enumerateIndexes
在 Objective-C 中,我的程序打开一个窗口并显示一个表格。我想要突出显示表格的指定行。 我该怎么做? 我似乎需要代码 [myTableView selectRowIndexes:(NSInd
假设我有 NSIndexSet 数组索引。我想根据 NSArray 对 NSIndexSet 进行排序。 所以,假设我们有数组: array = @[1,4,3,8,6,2,9]; 和索引集 inde
这感觉像是一个愚蠢的问题,因为在我看来我的用例一定很常见。 假设我想用 NSIndexSet 表示一组稀疏索引(这当然是它的用途)。我可以使用 -firstIndex 获取最低的索引,使用 -last
NSArray 有有用的方法来查找指定索引的对象 // To find objects by indexes - (id)objectAtIndex:(NSUInteger)index - (NSAr
我对 Cocoa 有点陌生,我正在阅读有关 NSIndexSet 的内容。为什么有必要?在我看来, NSIndexSet 只是一个 NSSet 整数,对吗?创建一个单独的集合的目的是什么? 最佳答案
在我的单元测试中,我查看了一些边界条件,但我的测试一直失败。当它的索引一直延伸到 NSNotFound-1(每个文档的最大合法值)时,我追踪到它通过索引集进行枚举。 使用这个测试代码: // Crea
我使用 https://stackoverflow.com/a/28964059/6481734 处的答案将 NSIndexSet 转换为 [Int] 数组我需要做相反的事情,将相同类型的数组转回 N
我想将 NSIndexSet 对象转换为 NSIndexPath,效果如链接:https://developer.apple.com/reference/photos/phphotolibrarych
在我验证它没有更多行后,我试图删除表中的一个部分,但我不确定我应该为 NSIndexSet 参数传递什么。这是我在其中使用的代码片段: public override void Com
我正在编写一种将数据从 TableView 复制到粘贴板的方法,但是如果选择了任何行,它应该专门只复制所选行中的数据,因此我需要遍历索引集 ... func createExportText(from
这个问题在这里已经有了答案: NSIndexSet "-indexAtIndex:"? (4 个答案) 关闭 9 年前。
我有一个非常简单的 Mac 应用程序,在某个特定时间,一个按钮会弹出一个带有输入字段的 NSAlert。之后我对 NSTableView 执行一些操作。如果用户按 OK 按钮,它工作正常,但如果用户按
我在下面第 4 行尝试重新加载表格的一部分时遇到错误。我也尝试使用 NSMakeRange([indexPath.section], 1) 但一直出现相同的错误。 override func tabl
我开始使用键值观察,而我正在观察的可变数组在更改字典中为我提供了 NSIndexSets (Ordered mutable to-many)。据我所知,问题是 TableView 希望我给它提供充满索
我从 TableView 中获取选择的项目: NSIndexSet *selectedItems = [aTableView selectedRowIndexes]; 在 NSArray 对象中获取索
我想弄清楚如何创建一组让我们说 (1, 2, 3) 的索引然后在 中使用它 - (void)selectRowIndexes:(NSIndexSet *)indexes byExtendingSele
我有这个代码: NSIndexSet *indexes = [anOrderedSet indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center . 已关
我是一名优秀的程序员,十分优秀!