In a broad sense, iPhone Development adopts the MVC model, namely Model-View-controller. Where:
The model is a data model, such as a user configuration file;
View is the displayed interface element, such as a button;
The Controller serves as a bridge between model and view. The view and model do not communicate directly, that is, the model can only communicate with the Controller, and the view can only communicate with the Controller.
In a simple app, there can be no model. For the sake of simplicity, this article does not design a model.
Now we assume there are two independent views: cnview and enview. The cnview and enview have two buttons and labels respectively. For cnview, When you click a button, the label displays "hello ", "Hello" is displayed for the enview ". The following uses this example to return to our focus.
1. Understanding of XIB files
The cnview and enview designed by IB correspond to an XIB file respectively. In the XIB file of cnview, the attributes of the button and label controls are described in XML format (the background and other attributes of the view are not taken into account here). There is a button and label, as well as the position and size of the button and label. The XIB file of enview is similar.
2. viewcontroller
Each view should have a View Controller (multiple views can adopt the same view controller, which will be discussed later). It can be seen as C in MVC (although not strictly), for example: the response action after clicking the button on the cnview interface is implemented by viewcontroller.
3. Relationship between XIB and viewcontroller
XIB is the performance. On the one hand, viewcontroller responds to operations (such as clicks and slides) on XIB and controls the display of XIB.
4. File's owner
The point is here. The relationship between views and viewcontroller requires a bridge to connect (that is, for a view, how does he know who should respond to the operations on his interface?) This bridge is the file's owner.
Select the file's owner of an XIB instance. In inspector, you can see the attributes: File Name and custom class, the file's owner is used to bind the XIB file in file name to the viewcontroller in custom class. After binding this file, press and hold the control key, when you drag the file's owner to a control in the XIB, The iboutlet element defined in the Custom class is connected to the element in the XIB. Similarly, when you drag "actions of controls in XIB" to the file's owner, the response of the action in XIB and the custom
The process of connecting an ibaction in class.
Therefore, when multiple XIB files exist, that is, multiple views are available. Different viewcontrollers can be used for each view, or the same viewcontroller can be used for all views, associate with the file owner.
In fact, the file's owner is a custom class object, and other elements in XIB are member variables of this object, however, you must manually associate the relationship between the member variables in custom class and objects in XIB.
5. First responder
In view, only one object interacts with the user at a time, and the current interaction object is first responder. For example, if you click the text box, the text box is first responder.
My description is not necessarily correct. please correct me.
[Reprinted, please specify the source]
Address: http://blog.csdn.net/donhao/article/details/7088446