2011-10-20 12 views
1

私は私の異なるケースの文字は同じセクションに行くために取得取得する方法を疑問に思って...の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

最も簡単な解決策は、常に最初の文字だけ大文字(または小文字)バージョンを格納することです。だからあなたは次のようなことをすることができます:

 NSString *firstLetter = [[value substringWithRange:NSMakeRange(0, 1)] uppercaseString]; 
+0

ああ。 は完全に働いた:)助けをありがとう:) –

関連する問題