2011-01-19 25 views
0

我在我的應用程序中使用iphones地址簿數據,我排序的數據和安排在UITableViewController,但現在我想使相同的外觀地址簿意味着排序在GroupedStyle具有初始字符爲的部分。而PLZ建議前往我如何安排排序的數據在UITableViewController

+0

你想要的東西像下面的鏈接http://stackoverflow.com/questions/4665310/sort-data-and-display-in-uitableview-on-iphone/4665728#4665728 – Tirth 2011-01-19 05:01:37

回答

1

您必須實現的tableView方法是

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

爲節頭和這個這個,你也必須實現

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

通過這樣做,你的表數據可以分組查看樣式。

1

使用類似下面的聯繫人排序:

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]]; 

從使用NSPredicate來接接觸,並將它們添加到您想要一節。

+0

我已經排序的數組,但現在我希望將表格作爲分組樣式具有第一個字符作爲章節標題 – Ali 2011-01-19 04:51:47