如何为大型数据集创建 UITableView 索引
我已经陷入了索引、分区、桌面视图的兔子洞,并被带上了一次让我想损坏我房间里很多有价值的物品的旅程……我希望最后一个清晰简洁的问题有人会能够帮助我解决这个持续的斗争。
我将从头开始,以免混淆任何提供帮助的人,我认为这样更容易,希望有人可以发布一些相当不错的示例供我阅读/使用,就像我认为我已经提供的之前的问题一样太多的细节让每个人都感到困惑,因为请求实际上很简单。它只是根据您输入的数据和方式来制定实现。
好的,我们开始吧。
我有一个 UITableView,当打开它时,它会查询我的数据库中的汽车制造商列表,我解析传入的 XML,并留下未排序的汽车制造商列表,然后我将此 NSArray 传递给一个自定义方法,然后对其进行排序 AZ 。
- (IBAction)startSortingTheArray:(NSMutableArray *)arrayData
{
//Sort incoming array alphabetically
[self setSortedArray:[arrayData sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]];
从这里我想知道如何为大型数据库的索引滚动制作索引 UITableview ..<<---- 这是我的问题
这是我所知道的,从这一点来看我需要创建一个字母数组,表示在我的数据中找到的字母表中的字母(即排序数组中每个值的第一个字母)。我还需要创建一个 NSDictionary,将排序后的数组分成该字典中的多个部分。
从那里我需要更新一些 UItableview 委托方法,以便它们可以处理 NSDictionary 和部分等。从那里我需要将 NSDictionary 中的值传递给我的 UItableviewcell 标签...
在之前的所有尝试中,我得到了到了我拥有一切的地步,但实际上能够将数据显示到表格视图单元格中,但因为它是通过阅读几个不同的教程组合在一起的,所以它不起作用。所以我现在想,我实际上有点知道需要发生什么,也许有人会很友善地分享他们的类似问题的代码,我将能够从中学习,并希望学习如何实际做到这一点......
我想感谢迄今为止帮助过我的任何人以及将来任何将要帮助我的人:PI 一定会发布我的最终解决方案并附上评论,希望能防止这种情况将来发生在其他人身上!我情不自禁地对苹果公司的这个泡菜实施感到有点仇恨。
Honda,
Honda,
Honda,
Honda,
Honda,
Honda,
Honda,
Mazda,
Mazda,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Toyota,
Toyota,
Toyota
I have gone down the rabbit hole of indexed, sectioned, tableviews and have been taken on a ride that has made me want to damage alot of valuable objects in my room... I am hoping with one last clear concise question that someone will be able to help me solve this on going struggle.
Im going to start from the beginning so as not to confuse anyeon that offers their help, I think its easier that way and hopefully someone can post some fairly decent examples for me to read/use, as in previous questions I think I have supplied to much detail and confused everyone where the request is actually simple.. its just the implementation is drawn out and dependant on what data you have coming in and how.
Okay here we go.
I have a UITableView which when opened queries my database for a list of car manufactures, I parse the XML that comes in and am left with a unsorted list of car manufactures, I then pass this NSArray over to a custom method that then sortes it A-Z.
- (IBAction)startSortingTheArray:(NSMutableArray *)arrayData
{
//Sort incoming array alphabetically
[self setSortedArray:[arrayData sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]];
From here I would like to know how to make a Indexed UITableview for Index Scrolling of a large database.. <<---- This is my question
Heres what I know, From this point I need to create an array of letters that represent the letters of the alphabet thats found in my data (i.e.) first letter of each value in my sorted array. I also need to create an NSDictionary with my sorted arrays split into sections withing this dictionary.
From there I need to update some of my UItableview delegate methods so that they can handle the NSDictionary and sections etc.. From there I need to pass the values in my NSDictionary over to my UItableviewcell labels...
In all previous attempts I have gotten to the point where I have everything but actually being able to display the data into the tableview cells, but because its been put together by reading several different tutorials its just not working. So I figured now that I actually kinda know what needs to happen maybe someone will be kind enough to share their code of a similar problem that I will be able to learn from and hopefully learn how to actually do this...
I would like to thank anyone that has helped me so far and anyone who is about to help me in the future :P I will be sure to post my final solution with comments to hopefully prevent this from happening to anyone else in the future! I cannot help but feel a slight amount of hatred towards apple for this pickle of an implementation.
Honda,
Honda,
Honda,
Honda,
Honda,
Honda,
Honda,
Mazda,
Mazda,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Mitsubishi,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Nissan,
Toyota,
Toyota,
Toyota
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从阅读你的问题来看,听起来你想要一个基于大型数据库的分段
UITableView
。你想分几个部分?它可以处理任意数量的数据,但有些功能您将无法使用,例如如果您有 100 多个部分,则index
-ing 可能不太好。 (事实上,我认为这可能有限制,但我不确定。)在这种情况下最简单的事情就是拥有一个数组数组。该数组将为每个部分保存一个数组。所以它会是这样的:
然后,在您的
UITableViewDelegate
方法中,使用:希望有帮助!
From reading your question, it sounds like you want to have a sectioned
UITableView
based on a large database. How many sections are you thinking? It can handle as many as you want, but there are some features which you will not be able to use, like theindex
-ing may not be great if you have 100+ sections. (In fact, I think there might be a limit on this, but I'm not sure.)The easiest thing to do in this case would be to have an array of arrays. The array would hold an array for each section. So it would be something like:
Then, in your
UITableViewDelegate
methods, use:Hope that Helps!