Contrast learning Uikit and appkit--Viewcontroller

Source: Internet
Author: User

The base class for Viewcontroller in iOS is Nsviewcontroller, which is the base class for Viewcontroller in Uiviewcontroller;mac.

Mac Viewcontroller Parent class is Nsviewcontroller, sub-class very few, the author found Nspagecontroller. If required in the application, you can customize.

There are many Viewcontroller in iOS, introduced in Ref2, the parent class is Uiviewcontroller, and subclasses include Uinavigationcontroller, Uitabbarcontroller, Uipageviewcontroller and so on. can also be customize.

How do you use Viewcontroller in your app? And what's the relationship between window and Windowcontroller? Let's talk about journal.

1. To create a window on a Mac, we need to specify the window's file ' owner, the file ' s owner needs to be a windowcontroller subclass, and iOS will not create a window, There is no need to windowcontroller, because the window on iOS is very simple, it does not need the title bars, close boxes, or any other visual adornments;

2. Whether on iOS or Mac, if we need to create a view in the Xib file, we need to specify the view's file ' owner, the file's owner needs to be a Viewcontroller subclass , or when Uiviewcontroller or Nsviewcontroller;

3. On the Mac, after creating a view of the Xib file, there will be a application placeholder object appearing in IB, as its category says, it is a placeholder,<tbd>;

4. After creating a window's Xib file on a Mac, it is not the same as when creating the view, where there is a column in the Xib of window, object, and placeholder when the Xib file of the view is created on Mac and iOS. This is due to the difference between window and view. Let's look at the three objects that Xcode adds to the default: Main Menu, App delegate, and font Manager. This topic needs another new post. <TBD>;

5. The difference between Mac and iOS is that Window,view is second to Mac, while iOS can say 99% is view. For example, we want to show a image+ a text description, on a Mac can usually pull in a window two view, a ImageView, a TextField view, and then handled by the Windowcontroller, Of course, you can create a customized view that includes a imageview, a TextField view, and a custom view controller, and iOS has a root view, Then you can do it like a Mac, but if an app has more pages, it's cumbersome to manage, one page displays an image, the other page is tab view, does it delete all the previous, add a new one, or a new window, then replace the current window? is not very natural, even if it can be achieved, the cost is much higher. So the best way to do this is to create a custom view, and then add an viewcontroller.

6. What does Viewcontroller do, and under what circumstances will customize view controller be required? View Controller is the C in UI design MVC pattern, for iOS uiviewcontroller, I wrote a blog post, did not dig into what, is to read Apple's documentation, scribble, generally speaking, there are a few features: View Management,rotation Management and so on. The main thing about Nsviewcontroller on Mac is the view management. The notable difference is that iOS needs to manage the period of view and expose several callback functions so that developer can customize when to do things, such as setting status in Viewwillappear Bar's orientation and style to make the status bar consistent with the view style to be displayed, and so on. When do I need customized Viewcontroller? This is common for Mac and iOS, and if you customize the view, you need to customize the Viewcontroller because the view controller needs to manage the view, how each button in the view is displayed, what the response is after the click, Support is provided for how awakefromnib is implemented.

7. Back to the beginning, why are there so many Uiviewcontroller subclasses on iOS and few nsviewcontroller subclasses on Mac? With a small display space on iOS and an efficient way to show how often, Apple has extracted several very common view types, providing Uiviewcontroller subclasses to help developers use them directly, thus shortening development time. And there is enough space on the Mac, developers can do it casually, it's hard to extract common patterns, even if there are few, but there are nspagecontroller to provide multi-page display, if you have this fixed mode in your application, you can provide a whole application to use.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.