Related information
Start developing iOS apps Now (start developing iOS apps today)
Apple Development Chinese station Cocoachina
Swift Development Official website
IOS Developer Library
The Swift programming language Chinese Full version
Inspector Panel
View Controller
Once you have built a basic view hierarchy, the next step is to control the visual elements and respond to user input. In an IOS application, you can use the view controller ( UIViewController ) to manage the content view and its sub-view hierarchy.
The view controller is not part of the view hierarchy, nor is it an element in the interface. Instead, it manages the view objects in the hierarchy and provides them with behavior. Each content view hierarchy that is built in a concatenation diagram requires a corresponding view controller to manage the interface elements and perform tasks to respond to user interaction. Typically, this means that you need to write a custom UIViewController Subclass for each content view hierarchy. If your application has multiple content views, you need to use a different custom view controller class for each content view.
The view controller plays a variety of roles. They are responsible for coordinating the transfer of information between the application's data model and the view that displays the data, managing the life cycle of the application's content view, and handling changes in direction when the device rotates. But its most important role may be to respond to user input.
You can also use a view controller to transform various types of content. Because the IOS app has a limited amount of space to display content, the view controller provides the infrastructure needed to remove the view from one view controller and replace it with a view from another view controller.
By having the view controller files communicate with the views in the inline diagram, you can define how the application interacts. The method is to define the connection between the concatenation diagram and the source code file through Action and Outlet
Action (Action)
Operation is a piece of code that is linked to some kind of event that may occur in an application. After the event occurs, the code executes. You can define actions to accomplish anything: from manipulating data to updating the user interface. Actions can drive the process of an application in response to user events or system events.
You can define this by using IBAction return types and sender parameters to create and implement methods.
-(ibaction)Restoredefaults:(ID)Sender;
sender The parameter points to the object responsible for triggering the action. IBActionThe return type is a special keyword. It void is similar to a keyword, but it means that the method is an operation that you can connect to in Interface Builder's concatenation diagram (this is the keyword that IB has The reason for the prefix). In Tutorial: Tandem diagram , you'll learn more about how to IBAction link an action to an element in a inline diagram.
Outlet
Outlet allows you to reference objects in the interface from source code files (objects added to the inline diagram). You can create a Outlet by holding down the Control key and dragging specific objects in the concatenation diagram to the view controller file. This creates a property for the object in the View controller file, which allows you to access and manipulate the object at run time through code. For example, in the second tutorial, you will create a Outlet for the text column in the ToDoList application so that you can access the contents of the Text field in code form.
Outlet is defined as a IBOutlet property.
@property(Weak,nonatomic)Iboutlet Uitextfield *TextField;
IBOutlet The keyword tells Xcode that you can connect to this property from Interface Builder. In Tutorial: Tandem diagram , you'll learn more about how to connect Outlet to source code from a concatenation diagram.
Controls (Control)
controls are user-interface objects (such as buttons, sliders, or switches) that users can manipulate to interact with the content, provide input, navigate within the application, and perform other actions that are defined. The code can receive messages from the user interface through control.
The user interacts with the control and creates a control event. A control event represents a variety of gestures that the user can use on the control, such as lifting the finger away from the control, dragging the finger to the control, and pressing in the text field.
There are three common types of events:
touching and dragging events. when users interact with the control by touching or dragging, they are touching and dragging events. Touch events are staged in several stages. For example, when a user touches a button for the first time, the touch down Inside event is triggered, and if the user's finger is dragged off the button, the corresponding drag event is triggered. Touch up Inside is sent when the user's finger is lifted off the button but still stays within the range of the button edge. The touch up Outside event is triggered if the user has pulled off the button (actually canceling the touch) before lifting his finger.
Edit event. the user edits the text field, and the edit event occurs.
The value Change event. the control is manipulated by the user, causing the control to produce a series of different values, which occur as value change events.
When defining an interaction, you should understand the actions associated with each control in your application, and then explicitly show the user the role of control in the application.
Navigation Controller
If your application has multiple levels of content view, you need to be able to switch between them. To do this, you can use a dedicated view controller: the navigation controller (uinavigationcontroller ). navigation The controller manages the move backwards and forwards in a series of view controllers, such as the user navigating between email accounts, inbox messages, and single e-mail messages in the IOS mail application.
We will refer to a set of view controllers managed by a particular navigation controller as its navigation stack. The navigation stack is a set of last-in-first-out custom View controller objects. The first item added to the stack becomes the root view controller and never pops up from the stack. Other view controllers can be pressed into or ejected from the navigation stack.
Although the primary role of the navigation controller is to manage how the content view controller is displayed, it is also responsible for displaying its own custom views. Specifically, it displays the navigation bar (the view at the top of the screen, providing context for the user's position in the navigation hierarchy). The navigation bar contains a return button and other customizable buttons. Each view controller added to the navigation stack will display this navigation bar. You need to configure the navigation bar.
In general, you do not have to take any action to eject the view controller from the navigation stack, and the return button provided by the navigation controller implements the operation. However, you need to manually press the view controller onto the stack. You can use a tandem chart to manipulate it.
Debug
Swift Learning first day