Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
Can someone point me to the method or info so I can read up on the alphabetical tableView separators that you find in the contacts list? I have seen them in a couple other programs and looked at the methods in the tableview thinking it would be there, but nothing stood out.

I first started to try to build something myself (code bellow) It was taking the first letter of a String at an index in my ClientArray, converting it to a Char and comparing the results. After tinkering for a hour I thought there had to be an easier way already made. The code is not done but this is what I was thinking. There must be a pre made solution for this? can I get any *'s in the right direction.

Code:
        int letterNum = 0;
        int count = clientListForTable.count;
        char currentLetter, arrayLetter;
        
        NSArray *letters = [[NSArray alloc]initWithObjects:@"A",@"B",@"C",@"D", nil];
 
        for (int i = 0; i < count; i ++) {
            NSString *charLetter = [clientListForTable objectAtIndex:i];
            currentLetter = [charLetter characterAtIndex:0];
            
            NSString *getLetterFromArray = [letters objectAtIndex:letterNum];
            arrayLetter = [getLetterFromArray characterAtIndex:0];
            
            while (currentLetter != arrayLetter) { // Find first letter
                letterNum++;
                NSString *getLetterFromArray = [letters objectAtIndex:letterNum];
                arrayLetter = [getLetterFromArray characterAtIndex:0];
            }
            
            [clientListForTable insertObject:[letters objectAtIndex:letterNum] atIndex:i];

            
        }

Thanks
 
Use Core Data...
sort everything alphabetically...
then run through the list grabbing the first letter of each name, and if the first letter of the current name matches the first letter of the prior name then it goes in the same section as the prior name, and if not, it starts a new section...

That's how I would do it.
 
there is
UILocalizedIndexedCollation
Never used it myself though. There is a discussion in the System Guides under the heading "Populating an Indexed List"

hth

Olaf
 
Thanks guys! I have not used Core Data for any projects as of yet. This might be a good time to learn them. I will read up on the UILocalizedIndexedCollation. I already sort my array so it is in alphabetical order. Thought it would have been easier to do this but I will read up on it.

Thanks.
 
Can someone point me to the method or info so I can read up on the alphabetical tableView separators that you find in the contacts list?

Do you mean the grey bars within the table that contain "A", "B", etc? Or do you mean the floating letters that run down the right side of the table?
 
My original question was in regards to the grey bar above the names that just contained the A,B,C and so on. But if it is easy then the one on the right side might be a good addition too.

I have not had time to read up on these yet and try them out. Family and holiday stuff get in the way of having fun learning this last week :)
 
The grey bars are what's known as section titles on a plain-style tableView. They are easily implemented using the UITableViewDataSource methods. As for the ones on the right side, those are called an indexed list. It might be a good idea to read through the entire Table View Programming Guide for iOS so you have a better idea of what all is available and possible with table views.
 
Ahh, thanks! today I have some time to finally work on this stuff. I will start to read the docs this afternoon.

Thanks again!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.