简体   繁体   中英

Using a UIView as a Controller

right now I'm concerning the structure of my App. I thought of subclassing UIView to make a "root view" that will perform as a Controller of the main flow of the app. So the subclass of UIView will have methods that will eg be invoked by Subviews, that perform the changes of the content, that is shown. Would you say this is a bad structure (/style) of programming, and if so, why is it bad or not elegant? Thanks for any Help :)

sh4kesbeer

Looks like a UIViewController, smells like a UIViewController, tastes like a UIViewController. So why not use a UIViewController?

Views must show something to the user; controllers must implement application logic. It means that is the controller that choose which view must be shown to the user.

If you want to study something more take a look to the apple documentation or what wikipedia says .

There's no logical difference of using UIView standalone or wrapped into UIViewController other than you are not using all the nice patterns designed for UIViewControllers like a standard callbacks, navController integration, tabBarController support, etc. Also makes your code listings larger and harder to read/understand.

However here's the main point, from the OOP perspective you are letting down encapsulation level affecting messaging as well. And now meet the killer: you are making C at MVC as small as it is barely visible from some points of view.

From my experience view based projects start just fine and then all kind of difficulties come to your door forcing you to think about refactoring which makes you to invent view controllers from scratch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM