_connections? , _connections . _connections .
, , NSMutableArray of NSMutableArray . , , , . :
NSString *currentPrefix;
sortedConnections = [[NSMutableArray alloc] init];
for (BRConnection *connection in _connections) {
NSString *firstLetter = [connection.fullName substringToIndex:1];
if ([currentPrefix isEqualToString:firstLetter]) {
[[sortedConnected lastObject] addObject:connection];
}
else {
NSMutableArray *newArray = [[NSMutableArray alloc] initWithObject:connection];
[sortedConnections addObject:newArray];
}
currentPrefix = firstLetter;
}
( , .)
, , [sortedConnections objectAtIndex:section] _connections:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [[sortedSearchResults objectAtIndex:section] count];
} else {
return [[sortedConnections objectAtIndex:section] count];
}
}
[sortedConnections objectAtIndex:indexPath.section]:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ConnectionCell"];
BRConnection *connection = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
connection = [[sortedSearchResults objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
} else {
connection = [[sortedConnections objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
}
cell.textLabel.text = connection.fullName;
cell.textLabel.font = [UIFont fontWithName:@"TitilliumText25L-400wt" size:18];
cell.detailTextLabel.text = connection.company;
cell.detailTextLabel.font = [UIFont fontWithName:@"TitilliumText25L-400wt" size:12];
return cell;
}