User recommendations of UIView and UIViewController?

I currently have a simple iPhone app that loads a custom subclass of UIView. At the moment, there is only one controller for the entire application, although there are several UIViews for the logical separation of the program.

My current structure looks something like this:

mainView : UIScrollView \__ has one subView : myCustomUIView : UIView \__ has many subSubView : myOtherCustomUIView : UIView 

Hope this is clear. the colon, of course, represents inheritance.

My problem is this: I need to intercept events at the lowest level of subSubView. Maybe I can do this in the application controller if I need it, but should I have a subSubViewController? Should I have a subViewController too?

If so, can someone point me to some links for this manually? I can, of course, create classes, but connecting them to user views seems nontrivial. I do not use the interface constructor at all, except for the main one, which contains the window object.

My main confusion arises from what happens when I have a view nested in a view with another controller. So let's say I had a subSubViewController, but the mainView still has its mainViewController. Since subSubView is contained in mainView, will this not cause any problem?

And should I use delegates at all for any of this?

Any push in the right direction would be appreciated.

+6
iphone cocoa-touch uiviewcontroller uiview
source share
1 answer

Views and view controllers exist in pairs. Each view controller controls the viewing and presentation of the view. This is necessary because view controllers are in the event responder chain. If multiple view controllers are active in the same view, the responder chain becomes scrambled.

Standard view controllers do not have a subController attribute and do not understand if another controller is active in the same chain. Navigation and table controllers exist precisely for managing hierarchical controllers. However, they do this by replacing one view / view-controller pair with another. You cannot use navigation controllers or tab bars to provide different controllers for prying.

Thus, no matter how many subtitles you can get for any view, you get only one controller per screen.

You might want to rethink your design. If each subzone requires very customizable behavior, you can move them into separate views in the controller hierarchy, for example, in the design template for the main parts.

If you need to have all the subitems on one screen, I would suggest looking at how UITableView and UITableViewController are handled. (Perhaps you can just use the modified table view.) Tableview is a scroll containing several subzones for cells, section headers, headers and footers. He manages this by grabbing strokes from the table and determining what kind of cells were affected, and then took appropriate action.

If you need a very individual behavior for each view, you can use the delegation template and assign each view a different delegate object. A view can catch its own touches and call its delegate.

Scrollviews can be tricky to implement individual touch behavior, as scrollview traps touch a higher level than other views so that it can determine whether it needs to be scrolled or not.

+10
source share

All Articles