Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of UIViewController for UITableView tableHeaderView

My question is mostly architectural in nature. I am using a UITableViewController to display a list of stuff. No big deal, pretty standard. However, the tableHeaderView contains a significant amount of functionality. There are a few tap targets, it animates, and the display changes based on user interaction. Currently I have a custom subclassed UIView handling most of the display logic and routing taps back through a delegate protocol to the UITableViewController for execution.

As more functionality gets added to the tableHeaderView, I feel as though my UITableViewController is becoming a bit cluttered and long. Thus I am curious if it makes sense to create a subclassed UIViewContoller and set its view to the tableHeaderView of my UITableViewController? If this is done, I would separate concerns a bit more and could house almost all of the logic in my new `UIViewController' I am guessing I would still need to route some communication via a delegate between the two viewControllers.

Does this make sense from an architectural perspective? Or should I just continue using the existing UITableViewController for all logic?

** EDIT **

For example, does this code make sense when placed in my UITableViewController

- (void)addHeader
{
    myCustomHeaderViewController *hvc = [[myCustomHeaderViewController alloc] init];
    //Assume the view for hvc is set up w/re to sizing, etc.
    self.tableView.tableHeaderView = hvc.view
}
like image 833
natenash203 Avatar asked Nov 11 '22 21:11

natenash203


1 Answers

Yes, you can do that, starting in iOS5 you have Containment View Controllers, so in one view controller you can add several child view controllers that will work together.

You can add your header view as a UIViewController and your table view as a UITableViewController in separate view controllers like this:

- (void) addViewController: (UIViewController*)content;
{
   [self addChildViewController:content];                 
   content.view.frame = [self frameForController];
   [self.view addSubview:self.currentClientView];
}

Here you can find a guide of how you can use them:

Creating Custom Container View Controllers

like image 100
Antonio MG Avatar answered Jan 04 '23 02:01

Antonio MG