objective-c - 如何使用 NSTableView 的 selectedRowIndexes?

标签 objective-c cocoa macos nstableview

我只是在学习 Objective C 和 Cocoa 的一些基本编程。我正在尝试从 NSTableView 获取一些数据。根据我在一个教程中阅读的内容,我写了这个:

NSArray * items = [[itemsTableView selectedRowEnumerator] allObjects];

但后来我了解到 selectedRowEnumerator 在 10.3 Panther 中已经被弃用,我应该使用 selectedRowIndexes

问题是,我没有找到如何实际使用返回的 NSIndexSet 来获得与上面编写的代码相同的结果。

所以,如果有人能给我提示,我将不胜感激。谢谢。

最佳答案

您可以像这样遍历 NSIndexSet 的索引:

- (void) goThroughIndexSet:(NSIndexSet *) anIndexSet
{
    NSUInteger idx = [anIndexSet firstIndex];

    while (idx != NSNotFound)
    {
        // do work with "idx"
        NSLog (@"The current index is %u", idx);

        // get the next index in the set
        idx = [anIndexSet indexGreaterThanIndex:idx];
    }

    // all done
}

关于objective-c - 如何使用 NSTableView 的 selectedRowIndexes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2843294/

相关文章:

ios - 启用/禁用某些类型的推送消息

ios - CloudKit:区域已被用户清除

swift - 如何检测 NSMenu 是否关闭?

ios - 如何在 iOS 中恢复非消耗品的 IAP

objective-c - 使用 Scripting Bridge 将电影添加到 iTunes

ios - iOS 和 Mac 设备之间的 Hand Off 无法正常工作

objective-c - 核心数据集属性

swift - Cocoa MacOS Swift/Objective-C 中的 Buggy NSPopupButton 不允许用户选择第一项

ruby - 由于符号链接(symbolic link)错误,无法在 Mac OSX 10.8.1 中安装 ruby​​-1.9.2

swift - windowShouldClose 报告未解析的标识符