开发者

How can I arrange sorted data in UITableViewController

开发者 https://www.devze.com 2023-02-05 15:55 出处:网络
I used iphones address b开发者_开发问答ook data in my app ,i sorted that data and arranged in UITableViewController,but now i want to make same look as of address book means sorted in GroupedStyle hav

I used iphones address b开发者_开发问答ook data in my app ,i sorted that data and arranged in UITableViewController,but now i want to make same look as of address book means sorted in GroupedStyle having initial character as heading of section .and suggestion plz


You have to implement the tableView methods that are

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

for section headers and for this this you also have to implement

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

By doing this your table data can be viewed in grouped style.


Use something like following to sort the contacts:

    NSArray* tempArray = [jsonData objectForKey:@"contacts"];
    NSSortDescriptor *sortDescriptor;
    sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"first_name"
                                                 ascending:YES] autorelease];
    NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    contactsArray = [[NSArray alloc] initWithArray:[tempArray  sortedArrayUsingDescriptors:sortDescriptors]];

From the use NSPredicate to pick the contacts and add them to section that you want.

0

精彩评论

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