开发者

AddressBookUI like TableView for my application?

开发者 https://www.devze.com 2022-12-14 23:33 出处:网络
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 开发者_如何学JAVAto have an A-Z index an

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 开发者_如何学JAVAto 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


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.


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.


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

0

精彩评论

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