title: How to add a UIToolbar to a UITableViewController programmatically?
body: <p>I have opted to use a <code>UITableViewController</code> without a nib. I need a UIToolbar at the bottom with two buttons. What is the simplest way of doing that?</p>
  
  <p>P.S. I know that I can easily use a <code>UIViewController</code> and add a <code>UITableView</code> however I want things to look consistent across the app. </p>
  
  <p>Can someone help?</p>
  
  <p>I saw the following example and I am not sure on its validity:</p>
  
  <pre><code>(void)viewWillAppear:(BOOL)animated {
      [super viewWillAppear:animated];
  
      //Initialize the toolbar 
      toolbar = [[UIToolbar alloc] init]; toolbar.barStyle = UIBarStyleDefault;
  
      //Set the toolbar to fit the width of the app. 
      [toolbar sizeToFit];
  
      //Caclulate the height of the toolbar 
      CGFloat toolbarHeight = [toolbar frame].size.height;
  
      //Get the bounds of the parent view 
      CGRect rootViewBounds = self.parentViewController.view.bounds;
  
      //Get the height of the parent view. 
      CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
  
      //Get the width of the parent view, 
      CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
  
      //Create a rectangle for the toolbar 
      CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);
  
      //Reposition and resize the receiver 
      [toolbar setFrame:rectArea];
  
      //Create a button 
      UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:@"back"
                                                                     style:UIBarButtonItemStyleBordered 
                                                                    target:self 
                                                                    action:@selector(info_clicked:)];
  
      [toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
  
      //Add the toolbar as a subview to the navigation controller.
      [self.navigationController.view addSubview:toolbar];
  
      [[self tableView] reloadData];
  }
  
  (void) info_clicked:(id)sender {
  
      [self.navigationController popViewControllerAnimated:YES];
      [toolbar removeFromSuperview];
  
  }
  </code></pre>