我只是在Objective C和Cocoa中学习一些基本的编程。 我正在尝试从NSTableView获取一些数据。 根据我在一个教程中读到的内容,我写了这个:
NSArray * items = [[itemsTableView selectedRowEnumerator] allObjects];但后来我了解到,在10.3 Panther中已经弃用了selectedRowEnumerator ,我应该使用selectedRowIndexes 。
问题是,我没有找到如何实际使用返回的NSIndexSet来实现与上面编写的代码相同的结果。
所以,如果有人能给我一个提示,我将非常感激。 谢谢。
I'm just learning some basic programming in Objective C and Cocoa. I'm trying to get some data from NSTableView. Based on what I read in one tutorial, I wrote this:
NSArray * items = [[itemsTableView selectedRowEnumerator] allObjects];But then I learned that selectedRowEnumerator was deprecated already in 10.3 Panther and that I should use selectedRowIndexes.
The problem is, I didn't find how to actually use the returned NSIndexSet to achieve the same result as with code written above.
So, If anyone could give me a tip, I would be very grateful. Thanks.
最满意答案
您可以循环遍历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 }You can loop through the indexes of an NSIndexSet like this:
- (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 }更多推荐
发布评论