/ Swift

Swift: Connect the UI to Source Code

ViewController

View controllers implement your app’s behavior. A view controller manages a single content view with its hierarchy of subviews. View controllers coordinate the flow of information between the app’s data model, which encapsulates the app’s data, and the views that display that data, manage the life cycle of their content views, handle orientation changes when the device is rotated, define the navigation within your app, and implement the behavior to respond to user input.

View controller负责实现APP的功能。一个view controller管理一个content view以及具备一定层次结构的subview。View controller对APP中负责封装数据的data model与负责显示数据的view之间的信息流动进行协调,管理content view的生命周期、处理设备的旋转事件、定义APP内的导航、以及对用户的输入进行响应。

Outlet

Outlets provide a way to reference interface objects—the objects you added to your storyboard—from source code files. To create an outlet, Control-drag from a particular object in your storyboard to a view controller file. This operation creates a property for the object in your view controller file, which lets you access and manipulate that object from code at runtime.

Outlet提供了一种在运行时通过代码操纵用户界面中对象的方法,这些对象都是由你添加到storyboard中的。要创建一个outlet,只需要按下Control并拖拽一个storyboard中特定的对象到view controller文件中。这个操作会在view controller中创建一个property,通过这个property你就可以在运行时使用代码来操纵这个特定对象。

Action

An action (or an action method) is a piece of code that’s linked to an event that can occur in your app. When that event takes place, the code gets executed. You can define an action method to accomplish anything from manipulating a piece of data to updating the UI. You use actions to drive the flow of your app in response to user or system events.

Action是指你的APP中与特定事件相关联的一段代码。事件被触发,代码即被执行。你几乎可以通过定义action方法来做任何事情,包括操纵一些数据甚至更新UI。使用action来驱动你的APP信息流以便对用户或者系统事件作出响应。

Yin Guobing

Yin Guobing

BOE技术研发工程师🔬,业余码农😳,蓝猫铲屎官🐈。曾独立开发了一款iOS APP并上线🎉。现居北京,正在为了理想中的生活而奋斗..

Read More