uitableview区分大小写

时间:2011-10-20 21:13:52

标签: iphone ios uitableview

我想知道如何让我得到不同的大小写字母进入相同的部分......

我将解析后的数据传递给一个自定义方法,该方法接收数组并创建如下所示的节字母。我只是不确定如何制作它以便大写和非大写字母出现在相同的部分中我希望得到一些帮助。

//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 个答案:

答案 0 :(得分:1)

最简单的解决方案是始终只存储第一个字母的大写(或小写)版本。所以你可以这样做:

        NSString *firstLetter = [[value substringWithRange:NSMakeRange(0, 1)] uppercaseString];
相关问题