开发者

Insert items into alphabetical sections in tableview

开发者 https://www.devze.com 2023-02-10 03:55 出处:网络
So, I have an array of various names and I have populated the table with section headers A-Z. Is it correct to find the first char of my data and then subsequently put it in the correct section, or

So, I have an array of various names and I have populated the table with section headers A-Z.

Is it correct to find the first char of my data and then subsequently put it in the correct section, or is there a way to do it using a faster method.

I believe what I am doing is wrong as I am thinking of making an A array for example and then find every element开发者_运维问答 starting with 'A' and insert it inside. But this is a bit crazy as then, I would need to create A-Z arrays which I seriously do not think that is the correct way.

I'm sorry if this is posted in the documentations but I don't seem to be able to find it.

Any help from you guys in this matter?


Well I actually did it this way, too and I don't see any reasons why this shouldn't be done, as it decouples the fetching / sorting process from refreshing the tableview, which in turn keeps loading and scrolling the tableview smooth.

Having A-Z arrays is not a big issue memorywise since they're just holding references to your data objects anyway and not the data itself. But it allows you fast access to your data objects without the need for expensive comparison operations. Just make sure your arrays are kept up to date if data objects are added or deleted.

0

精彩评论

暂无评论...
验证码 换一张
取 消