Note that there are some explanatory texts on larger screens.

plurals
  1. POAlphabetical sorting of UITableView iOS
    primarykey
    data
    text
    <p>I have a <code>UITableView</code> in iOS with a list of clients that I need to sort alphabetically.</p> <p>The sort button sorts my clients alphabetically:</p> <pre><code>-(void)prepareSortedClients { //Check if my clients are sorted, then create the index and clients if (!self.alphaKeys) { //No list of appropriate characters for side index, create it NSMutableSet *alphaSet = [[NSMutableSet alloc] init]; for ( RMClients *thisClient in self.clients ) { if ( thisClient.name &gt; 0 ) [alphaSet addObject:[thisClient.name substringToIndex:1]]; } NSArray *indexArray = [[alphaSet allObjects] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; self.alphaKeys = indexArray; } if (!self.sortedClients) { //Clients are not sorted, do it self.sortedClients = [[NSMutableDictionary alloc] init]; //Create a set of all the client objects NSSet *allClients = [NSSet setWithArray:self.clients]; //go through alpha keys and populate Dictionary with the appropriate clients for (NSString *thisAlphaKey in self.alphaKeys) { //get all clients starting with this key NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name beginswith[c] %@",thisAlphaKey]; NSSet *filteredSet = [allClients filteredSetUsingPredicate:predicate]; //the filteredSet now contains only the clients starting with this letter. Now, sort them and set the sortedClients's corresponding key to this array [self.sortedClients setObject:[[filteredSet allObjects] sortedArrayUsingSelector: @selector(localizedCaseInsensitiveCompare:)] forKey:thisAlphaKey]; } } </code></pre> <p>This takes care of sorting and everything looks great; my clients are sorted according to the client title with the proper section and everything. The issue I am experiencing is that I have 4 buttons in each cell (it gives you additional info specific info about the company (overview, financials etc).</p> <p>Now my original list without it being sorted I get these buttons going to the proper place and displaying information about the client in that cell.</p> <p>Now in the alphabetical sort I get the sort for the client with the letter "A" directed to the proper client page... now if I click on one of the buttons for a specific client under the letter "B" I still get the first client under the letter "A".</p> <p>So I am not getting that sort for the remaining clients even though they are displayed there.</p> <p>Any idea where I messed up?</p> <p><strong>---Additional code--- (This is where I refer to the buttons in my code)</strong></p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { RMCustomClientCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ClientCell"]; RMClients *client; if(!self.alphaMode){ client = [self.clients objectAtIndex:indexPath.row]; } else { NSString *key = [self.alphaKeys objectAtIndex:indexPath.section]; NSArray *specificClients = [self.sortedClients objectForKey:key]; client = [specificClients objectAtIndex:indexPath.row]; } cell.financialDetailsButton.tag = indexPath.row; cell.overviewDetailsButton.tag = indexPath.row; cell.pressReleaseDetailsButton.tag = indexPath.row; cell.eventsDetailsButton.tag = indexPath.row; cell.nameLabel.text = client.name; cell.symbolLabel.text = client.symbol; [cell.logoView setImageWithURL:[NSURL URLWithString:client.logoURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload