niklassaers
niklassaers

Reputation: 8810

AddressBookUI like TableView for my application?

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

Upvotes: 0

Views: 1257

Answers (3)

gerry3
gerry3

Reputation: 21460

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.

Upvotes: 3

niklassaers
niklassaers

Reputation: 8810

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

Upvotes: 0

Ben Gottlieb
Ben Gottlieb

Reputation: 85522

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.

Upvotes: 1

Related Questions