0
votes

I have a compex UIViewController (and related view). It consists of several subviews with their own view controllers. (e.g. few UITableViewController subclasses, custom ViewContorllers etc.).

Do you think that will be a good decision to store references of child view controllers in the root View (not view controller class). I'm building the view structure in the root view class right now like that (one of the few methods for adding view/viewcontroller):

- (void)addCaroucel
{
  _caroucelViewController = [[CaroucelTableViewController alloc] init];
  _caroucelViewController.caroucelView.delegate = self;
  [self addSubview:_caroucelViewController.caroucelView];
}

I understand that controllers somehow should be in main controller but in the same time this is like internal implementation of the view and I don't want to disclose it with main view controller. And I think that view hierarchy should be build in the view class, not in the view controller.

Do you see any better solution?

1
may be I did not understand your question but how about custom content view controller? developer.apple.com/library/ios/#featuredarticles/…stosha

1 Answers

0
votes

I think that better solution is:

One ViewController for one screen. All tableViews, buttons, views, etc... have got one common delegate - this viewController. Don't try separate your logic for some controllers. You try to add another view controller because of you have separated yet.

Also I know two bad ways in my opinion, they aren't so straightforward in this case:

  1. You can create singleton class as a manager for this controllers. It'll handle all logic from this controllers, but don't create a 'god' class.
  2. All controllers are separated and observe/post messages via Notification mechanism.