views:

467

answers:

3

Hi guys,

I've got a table-view with more than a thousand entries! That's just crazy, I know, but it makes no sense to split it into a tree. So what I'd like to do is to have an A-Z index and a search-bar just like in address book.

Is there such a framework around that lets me set my own datasource that has nothing to do with people and display it like in the address book?

Cheers

Nik

+1  A: 

Index tabs are easy, just implement -sectionIndexTitlesForTableView: in your table view's datasource. It should return an array of strings, for example, A, B, C,...Z.

Ben Gottlieb
Thank you very much :-)
niklassaers
A: 

Found a great answer here: http://blog.webscale.co.in/?p=240

Short answer, use tableView:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    NSMutableArray *toBeReturned = [[NSMutableArray alloc]init];
    for(char c = 'A'; c <= 'Z'; c++) [toBeReturned addObject:[NSString stringWithFormat:@"%c",c]];
    return toBeReturned;
}

Cheers

Nik

niklassaers
+3  A: 

Table views with thousands of entries are fine, but you definitely want fast scrolling and searching.

For scrolling, implement the table view datasource methods sectionIndexTitlesForTableView: and tableView:sectionForSectionIndexTitle:.

For searching, add a UISearchBar and implement some of its delegate methods. You may also want to a UISearchDisplayController which lets you use your controller as the datasource/delegate for its separate search table view. It also has a delegate protocol. Check out Apple's sample TableSearch.

gerry3
Thanks a bunch :-)
niklassaers