2011-10-20 44 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]; 
} 

這是它看起來像ATM ..

回答

1

最簡單的辦法就是始終只存儲第一個字母的大寫(或小寫)版本。所以你可以這樣做:

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

啊..很酷。 完美工作:)感謝您的幫助:) –