如何在UITableView中显示NSSet? [英] How to display an NSSet in a UITableView?

查看:64
本文介绍了如何在UITableView中显示NSSet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何继续在UITableView中显示NSSet的内容?

如您所知,表视图将在给定的行中请求该元素,但是由于NSSet元素未排序,因此不能很好地混合使用.

我当前的解决方案是遍历NSSet直到到达给定索引处的元素,但这确实感觉不对.

您可能会问为什么我不使用NSArray.这是因为我使用的是Core Data,它使用NSSet s存储元素集合.

任何帮助将不胜感激.

解决方案

由于只显示元素,为什么不采用NSSet,然后在其上调用-[allObjects]以获得NSArray?

如果数据发生更改,则无论如何都必须重新获取,即使使用NSSet,并且除了NSSet的初始转换之外,使用数组的速度也非常快.

How would you proceed to display the content of an NSSet in a UITableView?

As you know, the table view will ask for the element at a given row, but since the NSSet elements aren't ordered, this doesn't mix well.

My current solution is to iterate through the NSSet until I reach the element at a given index, but this really doesn't feel right.

You may ask why I don't use an NSArray instead. This is because I'm using Core Data, which uses NSSets to store collection of elements.

Any help would be appreciated.

解决方案

Since you're only displaying the elements, why not take the NSSet, and call -[allObjects] on it to get a NSArray?

If your data changes, you'll have to re-fetch anyway, even with a NSSet, and apart from the initial conversion from the NSSet, using the array is quite fast.

这篇关于如何在UITableView中显示NSSet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆