0

UITableView在 iOS 中有一个需要按字母顺序排序的客户端列表。

排序按钮按字母顺序对我的客户进行排序:

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

这负责排序,一切看起来都很棒;我的客户是根据客户标题与适当的部分和所有内容进行排序的。我遇到的问题是每个单元格中有 4 个按钮(它为您提供有关公司的其他信息特定信息(概述、财务等)。

现在我的原始列表没有被排序,我将这些按钮放到正确的位置并在该单元格中显示有关客户端的信息。

现在在字母排序中,我得到了客户的排序,字母“A”指向正确的客户页面......现在,如果我点击字母“B”下的特定客户的按钮之一,我仍然会得到字母“A”下的第一个客户。

因此,即使它们显示在那里,我也不会为其余的客户得到那种排序。

知道我在哪里搞砸了吗?

---附加代码---(这是我在代码中引用按钮的地方)

- (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;
}
4

0 回答 0