title: Objective-C numberOfSectionsInTableView - Query to return sections alphabetically
body: <p>I currently have a working TableView Application with a back-end sqlite database to feed the data.  The first view returns all states with a static heading of "States".  I would like to change that to return the states in alphabetical sections (ex. Alabama, Alaska, Arizona, Arkansas would fall under section called 'A' -- California, Colorado, Connecticut would fall under a section called 'C', etc).  </p>
  
  <p>My appdelegate calls a query to 'select id, state from state'.  I have what I believe to be working code to create the sections below (I have tested this by creating a NSMutableArray with just states as the objects and it worked fine).</p>
  
  <pre><code>stateIndex = [[NSMutableArray alloc] init];
  
  for (int i=0; i&lt;[listOfStates count]-1; i++){
      //---get the first char of each state---
      char alphabet = [[listOfStates objectAtIndex:i] characterAtIndex:0];
      NSString *uniChar = [NSString stringWithFormat:@"%C", alphabet];
  
      //---add each letter to the index array---
      if (![stateIndex containsObject:uniChar])
      {            
          [stateIndex addObject:uniChar];
      }        
  }
  </code></pre>
  
  <p>With no warnings/errors, I run simulator but it crashes.  After a short while, it dawned on me as to why it is crashing.  I am attempting to look for a alphabetical character during the search but due to the fact that the original query calls both an id and the state name, it is looking at the id and failing.  The id is needed in the search as it is linked to another table that loads cities based upon the state selected.  the id is the primary key.</p>
  
  <p>So, my question is...IS there a way to strip off or have the id field skipped during this search to create the alphabetical sections?</p>
  
  <p>Thank you in advance!</p>
  
  <p>UPDATED SchoolHouse.h ========</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;sqlite3.h&gt;
  
  @interface SchoolHouse : NSObject {
  
  }
  
  @property (assign, nonatomic, readonly) NSInteger schoolHouseID;
  @property (copy, nonatomic) NSString *schoolHouseName;
  
  
  -(id) initWithSchoolHouseData:(NSInteger)pk schoolHouseName:(NSString *)name;
  
  @end
  </code></pre>