Using UIViewController for UITableView tableHeaderView

My question is mostly architectural. I am using a UITableViewController to display a list of things. Nothing special, pretty standard. However, tableHeaderView contains significant functionality. There are several targets, they come to life, and the screen changes depending on user interaction. I currently have a custom subclass of UIView that handles most of the routing display and debug logic back through the delegate protocol to the UITableViewController to execute.

As additional functions are added to tableHeaderView it seems to me that my UITableViewController getting a little cluttered and long. So, I wonder if it makes sense to create a subclass of UIViewContoller and set its view to tableHeaderView my UITableViewController ? If this is done, I would be a little distracted from the problems and could place almost all the logic in my new "UIViewController". I assume that I still need to forward some communication through the delegate between the two viewControllers.

Does this make sense in terms of architecture? Or should I continue to use the existing UITableViewController for all the logic?

** EDIT **

For example, does this code make sense if it is 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 } 
+4
source share
1 answer

Yes, you can do this, starting with 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 a header view as a UIViewController and your view as a UITableViewController in separate view controllers, such as:

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

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

Create custom container view controllers

+1
source

Source: https://habr.com/ru/post/1502852/


All Articles