In any language, architectural design always plays an important role in it, and a good architectural idea can make the process of the program clearer and make the program work more simple and effective. If there is no architectural thinking, then all the programming will go along a design approach, the program will be completely lost vitality, only a uniform code to write, modify, debug, with the code architecture, we will put more energy into the program's thinking, Devote more time and energy to creating a structure that facilitates programming, which will make the structure of the program more diversified and convenient, and will make you more effective in the process of learning and working.
Said so much, there seems to be no strong evidence to confirm such a few words, we create a user login page of the process as a purpose to see the differences between different architectural methods, then we will use the following two architectural ideas to do a comparative analysis, the main function implementation as shown (arrows shown as jump direction): (1 The user should use the Userguide page at the first sign-in, (2) the user should be authenticated when they enter the login page for the first time, (3) The user should enter the homepage directly when remembering the password, (4) Return to the main page on logout.
(i) Use the navigation controller to switch between views (as shown in the image on the left)
First of all, why the Tabbar as the root controller of window: Because in the normal execution of the program, we usually operate on the main page, has no relation to the User Guide page and login page, if the use of the pilot after the login sequence, and then make the corresponding judgment, Push into the appropriate controller, then after entering the main interface our user Guide page and login page will always exist at the bottom of the navigation controller, can not be released to occupy the system memory space situation.
of this program to see, through the push mode of the controller, the correlation is too large, the files are contained in each other, the coupling is too strong. For example, in the login process, we need to determine whether to first login, if it is the first time, we push directly to the Userguide controller, and then to the LoginPage page to complete the login, due to window Rootviewcontroller is the main page, so we just need poptorootviewcontroller to be able to go back to the main page, but in Fourthview, we log off back to the login page and use push to LoginPage. This way, throughout the execution of the program, the files are included in each other, resulting in too much dependency between the files.
(b) We create a class that uses this class to convert the controllers to each other (as shown on the top right)
In view of the disadvantage of the above method, we adopt a more convenient and effective method, create a class to manage the switch between pages, by changing the window Rootviewcontroller, so that during the login process, Controller between the switch can be completely in class, and the controller is independent of each other, the relationship between the file is greatly reduced, on any page, as long as the inclusion of class classes can jump to the controller contained in it, from the structural view, The process is clearer, clearer, and easier to structure than the previous one.