0

Thank you for helping out in advance.

Trying to Autogroup UITableView alphabetically by following this solution: yasirmturk solution But I am stuck at this part where he said:

After that filter by alphabets:

NSArray *sectionArray = [vendorList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [self.sections objectAtIndex:section]]]; 
        rowCount = [sectionArray count];

Question: Where should I put the NSArray *sectionArray code? More specifically?

Current Status:Current Status (repeated array without filtering)

Expected Result:

1) "Egg Benedict" should be under "E" section and "Ham and Egg Sandwich" under "H" section.

Community
  • 1
  • 1
wkho899
  • 11
  • 1
  • 5
  • @yasirmturk mind to help out? – wkho899 Dec 02 '13 at 09:50
  • Got it by adding it in - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section and - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath =) – wkho899 Dec 02 '13 at 10:17

1 Answers1

1

Got it by adding it in

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(self.isFiltered){
        NSArray *filteredSectionArray = [filteredTableData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [arrSectionsHeader objectAtIndex:section]]];
        return [filteredSectionArray count];
    }
    else{
        NSArray *sectionArray = [allTableData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [arrSectionsHeader objectAtIndex:section]]];
        return [sectionArray count];
    }
}

and

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//....
    if (isFiltered) {
        NSArray *filteredSectionArray = [filteredTableData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [arrSectionsHeader objectAtIndex:indexPath.section]]];
        cell.nameLabel.text =[filteredSectionArray objectAtIndex:indexPath.row];
    }else{
        NSArray *sectionArray = [allTableData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [arrSectionsHeader objectAtIndex:indexPath.section]]];
        cell.nameLabel.text = [sectionArray objectAtIndex:indexPath.row];
    }
//....
}

=)

wkho899
  • 11
  • 1
  • 5