Answer the question
In order to leave comments, you need to log in
How to index a table from an array of objects?
Good time of the day! I have an array and a class with properties, in which I map the data, here is an example:
...
Customers *customers;
NSMutableArray *arrayCustomers;
...
for (NSDictionary *dictionary in [responseData objectForKey:@"data_list"]) {
customers = ;
Answer the question
In order to leave comments, you need to log in
...
Customers *customers;
NSMutableDictionary *dictionaryCustomers;
NSArray *sortedKeys = nil;
...
for (NSDictionary *dictionary in [responseData objectForKey:@"data_list"]) {
customers = obkectAtIndex:indexPath.row];
...
return cell;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return sortedKeys;
}
@interface MyViewController ()
@property NSMutableDictionary *dictionaryCustomers; // исходные которые были заполненны из responseData
@property NSArray *sortedKeys; // исходные которые были заполненны из responseData
@property NSDictionary *currentDictionaryCustomers;
@property NSArray *currentSortedKeys;
@end
@implemented MyViewController
- (void)parseResponse:(id)responseData
{
// парсим ответ
self.dictionaryCustomers = ...
self.sortedKeys = ...
self.currentDictionaryCustomers = self.dictionaryCustomers;
self.currentSortedKeys = self.sortedKeys;
}
- (void)filterCustomers:(NSString *)sFilter
{
NSMutableDictionary *result = [NSMutableDictionary new];
for (NSString *key in [self.dictionaryCustomers allKeys])
{
for (Customers *customer in self.dictionaryCustomers[key])
{
if (<customer.company содержит sFilter>)
{
if ([result.allKeys containsObject:key] == NO) result[key] = [NSmutableArray new];
[result[key] addObject:customer];
}
}
}
self.currentDictionaryCustomers = result;
self.currentSortedKeys = [result.allKeys sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
return [obj1 compare:obj2];
}]
[self.tableView reloadData];
}
// тут заполняем tableView из self.currentDictionaryCustomers и self.currentSortedKeys
@end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question