title: Creating a UITableView Programmatically
body: <p>I have an application in Xcode 4.6 which uses storyboards. I added a UITableView to a view controller class, which worked as expected. However, when I tried deleting the UITableView in the storyboard and adding it back into the same class programmatically, I ran into two specific problems:</p>
  
  <p><strong>1) Although I set the UITableViewCell type to be of type subtitle, the detail label no longer appears.</strong></p>
  
  <p><strong>2) The segue that should occur when I select a cell does not occur, and prepare segue is not even being called, indicating that no message is being sent to the table view when a cell is selected.</strong> </p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>@interface StatsTableViewController () &lt;UITableViewDataSource, UITableViewDelegate&gt;
  @property (strong, nonatomic) UITableView *tableView;
  
  @end
  
  @implementation StatsTableViewController
  
  -(UITableView *)makeTableView
  {
      CGFloat x = 0;
      CGFloat y = 50;
      CGFloat width = self.view.frame.size.width;
      CGFloat height = self.view.frame.size.height - 50;
      CGRect tableFrame = CGRectMake(x, y, width, height);
  
      UITableView *tableView = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];
  
      tableView.rowHeight = 45;
      tableView.sectionFooterHeight = 22;
      tableView.sectionHeaderHeight = 22;
      tableView.scrollEnabled = YES;
      tableView.showsVerticalScrollIndicator = YES;
      tableView.userInteractionEnabled = YES;
      tableView.bounces = YES;
  
      tableView.delegate = self;
      tableView.dataSource = self;
  
      return tableView;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      self.tableView = [self makeTableView];
      [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"newFriendCell"];
      [self.view addSubview:self.tableView];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"newFriendCell";
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  
      if (cell == nil) 
      {
          cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
      }
  
      Friend *friend = [self.fetchedResultsController objectAtIndexPath:indexPath];
  
       **//THIS DATA APPEARS**
      cell.textLabel.text = friend.name;
      cell.textLabel.font = [cell.textLabel.font fontWithSize:20];
      cell.imageView.image = [UIImage imageNamed:@"icon57x57"];
  
      **//THIS DATA DOES NOT APPEAR**
      cell.detailTextLabel.text = [NSString stringWithFormat:@"%i Games", friend.gameCount];
      cell.detailTextLabel.textColor = [UIColor lightGrayColor];
  
      return cell;
  }
  
   -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      [self performSegueWithIdentifier:@"detailsView" sender:self];
  }
  
  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  {
        //I set the segue identifier in the interface builder
       if ([segue.identifier isEqualToString:@"detailsView"])
       {
  
           NSLog(@"segue"); //check to see if method is called, it is NOT called upon cell touch
  
           NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
           ///more code to prepare next view controller....
       }
  }
  </code></pre>
  
  <p>I am not sure what I am forgetting to do so that I can solve these two issues. Any help is appreciated.</p>