如何使用NSTableView的selectedRowIndexes?(How to use NSTableView's selectedRowIndexes?)

编程入门 行业动态 更新时间:2024-10-17 17:24:02
如何使用NSTableView的selectedRowIndexes?(How to use NSTableView's selectedRowIndexes?)

我只是在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 }

更多推荐

本文发布于:2023-08-04 09:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   NSTableView   selectedRowIndexes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!