1

image.png

首先,StoryBoard 中定义好的 ViewController 的 class 应该要填和这里的 ViewController.swift 中定义的类同名。这样故事板才会和 .swift 文件联系在一起、支持连线操作。

定义 action 函数,设定 sender 为 UIButton ,可以发现函数左边出现了小加号。

Untitled.png

点住小加号可以拖出一条线,线指向的地方就是要绑定的目标。

Untitled 1.png

松开就可以完成绑定。实现点击按钮就可以执行到相应函数。

Untitled 2.png

这时到 Main.stotyboard  中看按钮到属性,它到 action 中, 多了一个 action。

Untitled 3.png

从 storyBoard 来绑定

进入 Main.storyboard 查看按钮的属性,点住它的 action 的小圈。

Untitled 4.png

把它连线到要要触发到函数上。

Untitled 5.png

松开就可以完成绑定。

Untitled 6.png


ZanxinZ
5 声望0 粉丝

iOS 开发,软件开发。