uitableview чувствительные к регистру разделы - PullRequest
1 голос
/ 21 октября 2011

Мне интересно, как заставить разные буквы падать в одни и те же разделы ...

Я передаю свои проанализированные данные в специальный метод, который берет массив и создает буквы разделов, как показано ниже ... Я просто не уверен, как сделать так, чтобы заглавные и не заглавные буквы появлялись в одних и тех же разделах надеялся на помощь.

//method to sort array and split for use with uitableview Index
- (IBAction)startSortingTheArray:(NSArray *)arrayData
{
     //If you want the standard array use this code
    sortedArray = arrayData;

    self.letterDictionary = [NSMutableDictionary dictionary];
    sectionLetterArray = [[NSMutableArray alloc] init];

    //Index scrolling Iterate over values for future use
    for (NSString *value in sortedArray) 
    {
        // Get the first letter and its associated array from the dictionary.
        // If the dictionary does not exist create one and associate it with the letter.
        NSString *firstLetter = [value substringWithRange:NSMakeRange(0, 1)];

        NSMutableArray *arrayForLetter = [letterDictionary objectForKey:firstLetter];
        if (arrayForLetter == nil) 
        {
            arrayForLetter = [NSMutableArray array];
            [letterDictionary setObject:arrayForLetter forKey:firstLetter];
            [sectionLetterArray addObject:firstLetter]; // This will be used to set index scroller and section titles
        }
        // Add the value to the array for this letter
        [arrayForLetter addObject:value];
    }      
    //Reload data in table
    [self.tableView reloadData];
}

вот как это выглядит атм ..

1 Ответ

1 голос
/ 21 октября 2011

Самое простое решение - всегда хранить только заглавную (или строчную) версию первой буквы.Так что вы можете сделать что-то вроде:

        NSString *firstLetter = [[value substringWithRange:NSMakeRange(0, 1)] uppercaseString];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...