title: iPhone contacts app styled indexed table view implementation
body: <p><strong>My Requirement:</strong>
  I have this straight forward requirement of listing names of people in alphabetical order in a Indexed table view with index titles being the starting letter of alphabets (additionally a search icon at the top and # to display misc values which start with a number and other special characters).</p>
  
  <p><strong>What I have done so far:</strong>
  1. I am using core data for storage and "last_name" is modelled as a String property in the Contacts entity
  2.I am using a NSFetchedResultsController to display the sorted indexed table view.</p>
  
  <p><strong>Issues accomplishing my requirement:</strong>
  1. First up, I couldn't get the section index titles to be the first letter of alphabets. Dave's suggestion in the following post, helped me achieve the same: <a href="https://stackoverflow.com/questions/1112521/nsfetchedresultscontroller-with-sections-created-by-first-letter-of-a-string">NSFetchedResultsController with sections created by first letter of a string</a></p>
  
  <p>The only issue I encountered with Dave' suggestion is that I couldn't get the misc named grouped under "#" index.</p>
  
  <p><strong>What I have tried:</strong>
  1. I tried adding a custom compare method to NSString (category) to check how the comparison and section is made but that custom method doesn't get called when specified in the NSSortDescriptor selector.</p>
  
  <p>Here is some code:</p>
  
  <pre><code>@interface NSString (SortString)
  
  -(NSComparisonResult) customCompare: (NSString*) aStirng;
  
  @end
  
  @implementation NSString (SortString)
  
  -(NSComparisonResult) customCompare:(NSString *)aString
  {
   NSLog(@"Custom compare called to compare : %@ and %@",self,aString);
   return [self caseInsensitiveCompare:aString];
  }
  
  @end</code></pre>
  
  <p><strong>Code to fetch data:</strong></p>
  
  <pre><code>NSArray *sortDescriptors = [NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"last_name"
                 ascending:YES selector:@selector(customCompare:)] autorelease]];
  
    [fetchRequest setSortDescriptors:sortDescriptors];
          fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
              managedObjectContext:managedObjectContext sectionNameKeyPath:@"lastNameInitial" cacheName:@"MyCache"];
  </code></pre>
  
  <p>Can you let me know what I am missing and how the requirement can be accomplished ?</p>