Apple, and thus most people who adhere to Appleβs principles, will tell you about their bad practices, and Apple has added ViewController (childViewControllers) controls for this reason. Unfortunately, most people blindly follow this and will not tell you why this is bad practice. And I'm glad you ask for it.
The truth is that in the model-view-controller architecture, views must be reused regardless of the content they contain, so the view and the object that controls the content of the view should not be the same. This is exactly what the UIViewController does before iOS5. Apple does not encourage you to use them in animators, while this is very logical. Of course, this was incomprehensible, many people ignored the recommendations and still did it, including applications, the applications worked fine and passed the application store check, which caused even more confusion. As a result, people still ask questions about this even more than a year after Apple crashed and provided us with custom ViewControllers containers. I saw how people often answered this question with complex answers to recreate the UIViewController as a class that inherits NSObject for very simple problems. Just because Apple does not recommend using UIViewControllers and not even knowing why.
Since adding a ViewController view as a subquery will often work fine, and holding a ViewController is not available in iOS4, which many still support, too many people don't care about holding a ViewController. This is a cleaner solution, and when you want to use ViewControllers in ViewControllers, you should use it whenever possible. If not, in most situations you should just add the ViewController view as a subheading, you just need to know in which situations.
Here you can expect if you just add the ViewController view to another view:
- Viewing callback methods is not guaranteed. Methods such as viewWillAppear, viewDidAppear, viewWillDisappear, and viewDidDisappear may or may not be called. This will largely depend on the OS version, in iOS4, which they will never call, in iOS5 and higher they will be mainly called. Thus, you cannot override these methods, because you cannot rely on them, you cannot control when, if or how many times they will be called.
- The only callback method that will always be called correctly is viewDidLoad.
- Rotation callbacks will not be called. Depending on your situation, this can be a big problem or no matter what. If the autoresizing view masks are enough to move and resize it, then you're fine. If not, you can always execute a custom implementation when the rotation callbacks of the viewview ViewController are called.
- You must store the link to the ViewController yourself, otherwise it will be released immediately, while its view is still saved by its add-in.
I definitely wonβt encourage him, but I donβt discourage him either. This is a situation, and if you no longer need to support iOS4, you can avoid it. But if you save the above list, it will not hurt, and your application will work fine.
David source share