title: How do I show details view in iPhone App using Sqlite
body: <p>I am trying out iPhone Apps, coming from C#, I am finding very difficult to grasp the iPhone dev environment.</p>
  
  <p>So far, I am able to get my 'Makes' listed in a TableViewController. I now wish to get by 'Models' listed when a Makes is selected. <strong>Can someone help me with sample code.</strong></p>
  
  <p>Can I use the same TableViewController to show the Models of the cars?</p>
  
  <p>I did not create any Nibs, I am doing all in code.</p>
  
  <p>The Sql for the details would be: select title from make where parentkey = ?
  The parentkey is the primarykey of the make.</p>
  
  <pre><code>//  MakeListTableViewController.h
  #import &lt;UIKit/UIKit.h&gt;
  #import "ModelTableViewController.h"
  
  @interface MakeListTableViewController : UITableViewController {
  NSMutableArray *makes;
  ModelTableViewController *modelTableViewController;
  UITabBarController *tabBarController;
  }
  
  @property (nonatomic, retain) ModelTableViewController * modelTableViewController;
  @property (nonatomic, retain) UITabBarController *tabBarController;
  
  @end
  
  //  MakeListTableViewController.m
  #import "MakeListTableViewController.h"
  #import "ModelTableViewController.h"
  #import "sqlite3.h"
  
  static int MyCallback(void *context, int count, char **values, char **columns)
  {
  NSMutableArray *categories = (NSMutableArray *)context;
  for (int i=0; i &lt; count; i++) {
      const char *titleCString = values[i];
      [makes addObject:[NSString stringWithUTF8String:titleCString]];
  }
  return SQLITE_OK;
  }
  
   @implementation MakeListTableViewController
  
  - (void)loadNamesFromDatabase
  {
  NSString *file = [[NSBundle mainBundle] pathForResource:@"CarList" ofType:@"sqlite"];
  sqlite3 *database = NULL;
  if (sqlite3_open([file UTF8String], &amp;database) == SQLITE_OK) {
      sqlite3_exec(database, "select title from make where parentkey = 0", MyCallback, makes, NULL);
  }
  sqlite3_close(database);
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section    {
  //return 0;
  return [makes count];
   }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  // THIS IS WHERE I THINK THE INDEX IS PASSED ON FOR THE DETAILS
  UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
  
  cell.text = [makes objectAtIndex:indexPath.row];
  
  //return cell;
  return [cell autorelease];
  }
  
  - (id)initWithStyle:(UITableViewStyle)style
  {
  self = [super initWithStyle:style];
  if (self) {
      makes = [[NSMutableArray alloc] init];
      [self loadNamesFromDatabase];
  }
  return self;
  }
  - (void)dealloc {
  [makes release];
  [super dealloc];
  }
  @end
  </code></pre>
  
  <p>SQL</p>
  
  <pre><code>CREATE TABLE make(pk INTEGER PRIMARY KEY, parentkey INTEGER DEFAULT 0, title TEXT);
  
  INSERT INTO make(title) VALUES('Honda');
  INSERT INTO make(title) VALUES('Toyota');
  INSERT INTO make(title) VALUES('Mazda');
  INSERT INTO make(title) VALUES('Nissan');
  
  INSERT INTO make(title, parentkey) VALUES('Civic', 1);
  INSERT INTO make(title, parentkey) VALUES('Accord', 1);
  INSERT INTO make(title, parentkey) VALUES('Corolla', 2);
  </code></pre>
  
  <p>In my C# programs I am used to using the primary key to get the details record, like the GridView, is this how it is also done in the iPhone?</p>