title: Implement Delegate at Run Time?
body: <p>I have a universal view controller class which all of the view controller classes in my app inherit from which has the following <code>loadView</code> method:</p>
  
  <pre><code>- (void) loadView
  {
      if (viewType == UIStandardViewControllerViewTypeUIView)
      {
          UIView *view = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
          [self setView: view];
          [view release];
      }
      else if (viewType == UIStandardViewControllerViewTypeUIScrollView)
      {
          UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
          [self setView: scrollView];
          [scrollView release];
      }
      else if (viewType == UIStandardViewControllerViewTypeUITableViewPlain || viewType == UIStandardViewControllerViewTypeUITableViewGrouped)
      {
          UITableViewStyle tableViewStyle; 
  
          if (viewType == UIStandardViewControllerViewTypeUITableViewPlain)
          {
              tableViewStyle = UITableViewStylePlain;
          }
          else 
          {
              tableViewStyle = UITableViewStyleGrouped;
          }
  
          UITableView *tableView = [[UITableView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] style: tableViewStyle];
          [self setView: tableView];
          [tableView release];
      }
  
      UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
      [[self navigationItem] setBackBarButtonItem: backButton];
      [backButton release];
  }
  </code></pre>
  
  <p>I have it done this way for a lot of reasons that I don't feel like getting into. Anyhow, as you'll notice, one of the view types to implement is a <code>tableview</code>. As we all know, a <code>tableview</code> needs a <code>delegate</code> and a <code>datasource</code>. I was wondering if it's possible to implement the <code>&lt;UITableViewDelegate, UITableViewDataSource&gt;</code> at run time when I know a tableView is the choice that was made?</p>
  
  <p>If not, does anyone else have any ideas how I can do this without having to manually implement my delegate and datasource in the inheriting view controller class? If I implement the data source and delegate at compile time (normally) in my <code>UIStandardViewController</code> class, then I get warning because I need to implement the mandatory data source and delegate methods in my standard view controller class. Would you implement these and then just override them in child class? Or anyone have any idea of how I can do this cleanly?</p>
  
  <p>UPDATE: Was wondering, if I just implemented the delegate and data source in my UIStandardViewController class, and also implemented empty versions of the required methods, would this be a lot of extra overhead when I didn't use a tableview?</p>