Creating a localized table index on the fly

Discussion in 'iOS Programming' started by idelovski, Jul 19, 2012.

  1. idelovski macrumors regular

    Sep 11, 2008
    I was about to create an array of first characters from the array of strings I use as titles in a UITableView and at first I wanted to have letters as separate entries and everything else (numbers, space characters, punctuation, etc.) grouped together as one item, something like what I can see in the Address Book.

    Well, then it occurred to me that people may enter arabic, chinese, japanese and all kinds of non latin names into my application. Now I have no idea where to start and what to do.

    Any pointers, documents by Apple or anyone else? Where should I start?
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    What is the app intended to do?

    The reason an Address Book is alphabetical is because it's an address book, and that's the traditional way of structuring address books.

    If you're making something that's like an address book, but needs to support multiple writing systems at the same time, then you could arrange multiple alpha-sorted indexes by language. More specifically, arrange by writing system or alphabet, since languages like French, Spanish, and English all use the same alphabet, but Russian and Greek have different alphabets. All the entries in Cyrillic would be under that section, and all the entries in Greek would be under that separate section.

    You could choose the first index based on the user's default language/writing system. A Russian user would see Cyrillic first, a Greek user would see Greek first, etc.

    The "other languages" would be dynamically constructed, not prepopulated for all possible first letters for all possible languages.

    But if you're not making something like an address book, then a completely different approach may be more appropriate.
  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    This is what UILocalizedIndexedCollation is for. Apple has sample code for this. It can't quite do everything you want but it gets you pretty far.
  4. idelovski, Jul 19, 2012
    Last edited: Jul 19, 2012

    idelovski thread starter macrumors regular

    Sep 11, 2008
    I'm not making an address book, just gave it as an example of a table with the index that should be familiar to everybody. Example with letters and # character at the bottom.

    But, let's say I'm making a web browser and I want an index when I display sorted history. You see, one can be a chinese person living in UK and studying Russian language and he's married to a Japanese girl studying arabic and they share the device and my application. Now, they can have all kinds of pages in their history.

    I would really like to have the index because it may be very useful to all the people who use mostly one alphabet, but I need to think about users that are mixing languages and alphabets.

    Not to mention the fact that I have no idea if such index is even possible with chinese, arabic, japanese, hebrew, ... Everybody who sells applications worldwide must have had a similar problems so I still hope this problem was solved long time ago by someone coming to this site.

    EDIT, as I was writing this PhoneyDeveloper posted his answer.

    Thank you.
  5. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    I don't know of an obvious collation order between writing systems. So if there are entries in multiple writing systems, there are various possibilities for how they'd be ordered in a single list. The simplest is to let UILocalizedIndexedCollation do whatever it does and leave it at that.
  6. idelovski thread starter macrumors regular

    Sep 11, 2008
    Well, crazy (or embarrassing) thing is I have this book: Pro iOS Table Views: for iPhone, iPad, and iPod touch, but I couldn't find anything browsing the book's index. The irony of it...

    Anyway, now when I know the name of the class that I need I've found it in the TOC. Yes, it is in the TOC, but not in the index. Index has no item "international" or anything related to it. But nevertheless, the book seem to have a solid example of UILocalizedIndexedCollation used to build the index of a table. Thanks everybody for the help.

Share This Page