Many views have a subspecies that need not have their own controller associated with them. In Apple’s own tutorial on creating custom views, they don’t actually create a sub UIViewController for each view.
However, I often encounter situations where I will have a hierarchy of views, where some subview has a button that sends a network request. In this case, I could make the goal:
myView.addTarget(self, action: "networkRequest:", forControlEvents: UIControlEvents.TouchDown)
And then in the same myView class, I could handle this network request, but that seems to break the MVC pattern. Viewing should not do logic, they should just display material, right?
Another option we could do is to have access to each view for this parent or grandparents controller, which is necessary for logic. In case my goal might look something like this:
func networkRequest(view : MyView) { self.controller.doNetworkRequest() }
But this is also not the right decision. Again, it looks like we're just breaking MVC and digging it out.
So, we left one of two options, as far as I saw:
First, we could add goals and all the logic from the parent controller itself. But doing this gives us nasty chains like this:
self.grandParentView.parentView.childView.addTarget(self, action: "networkRequest:", forControlEvents: UIControlEvents.TouchDown)
This long access list gives me chills and just looks bad. But apparently this is similar to MVC. Technically, we do the logic in the controller, right?
But there may be another option. We could just give each kind of controller and each UIViewController have a sub-controller for each new subview.
But some views are static. They really have no logic, so they do not necessarily need a controller. But we essentially need one for each view if we follow this convention, otherwise we have inconsistencies when the controller has a grandson controller but no child controller.
So, we have left the creation of empty boxes for our controllers. This creates a lot of dead code that is never used, which can lead to a software crash.
So, who is smarter and wiser than me , what is the right decision here?