今天分享如何把storyboard关联到view controller,即实现当view点击的时候,触发哪些事件。
具体如下:
Every scene in a storyboard references a view controller class that contains the code that manipulates the view. If you have multiple scenes in the storyboard, select the scene and click the Identity inspector () to get the associated view controller class. To connect objects on the canvas to your code, open the assistant editor and in the editor selection bar (which appears at the top of the assistant editor), choose Automatic followed by a class implementation file—for example, choose ViewController.swift.
Add an outlet if you want to reference an interface object in your code—for example, change its value at run time. To create an outlet, Control-drag from the object on the canvas to the code in the assistant editor where property declarations are allowed. In the dialog that appears, enter the property name and click Connect.
To add an action method that is called when the user interacts with a control (taps a button, enters text, or moves a slider), Control-drag from the control to the method implementation section of the class source file. In the dialog that appears, enter the method name, and click Connect (optionally, specify the types and event that invokes the action). You can enter the code now for the action method or later using the source editor.