我只是在学习 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/

10-13 06:30