To programmaictlly change the content of app, we need to contect storyboard to a view controller.

To do that, we need to create new file call it 'ProductViewController', subclass should UIViewController:

Delete some uncessary code, the remain code should looks like:

import UIKit

class ProductViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad() }
}

Link view to controller:

Click the view panel, and on the right side give the Custom class name as 'ProductViewController':

Link ui elements to outlets:

Click 'ctrl' & drag the image point to the code:

Give the name and save.

We can use 'Image Literal' to auto select the image:

DO the same for the label,  then the code looks like:

import UIKit

class ProductViewController: UIViewController {

    @IBOutlet weak var productNameLabel: UILabel!
@IBOutlet weak var productViewImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad() productNameLabel.text = "1937 Desk Phone";
productViewImage.image = #imageLiteral(resourceName: "phone-fullscreen3");
}
}

class CourseViewController : UIViewController {

  @IBOutlet weak var courseNameLabel: UILabel!
@IBOutlet weak var courseImageView: UIImageView! override func viewDidLoad() {
super.viewDidLoad() var courseName = "App Evolution With Swift" courseNameLabel.text = courseName
courseImageView.image = UIImage(named: "course-badge")
}
}

    @IBAction func addProductAction(_ sender: UIButton) {
print("Button tapped")
}

[Swift] Storyboard outlet and action的更多相关文章

  1. swift - storyboard(故事版)的使用

    iOS开发中,苹果公司提供了一种可视化的编程方式:即xib和storyboard,xib相对来说比较灵活,可以在纯代码的项目中使用, 也可以和storyboard配合使用,用法都差不多,下面来总结一下 ...

  2. IOS Note - Outlet(插座) & Action(动作)

    OutletActionViewController.h #import <UIKit/UIKit.h> @interface OutletActionViewController : U ...

  3. Swift Storyboard找不到类文件

    Swift语言引入了Module概念,在通过关键字@objc(类名)做转换的时候,由于Storyboard没有及时更新Module属性,会导致如下两种类型错误: 1 用@objc(类名)标记的Swif ...

  4. Swift语言Storyboard教程:第一部分

    更新记录: 该Storyboard教程由Caroline Begbie更新iOS 8和Swift相关内容.原文作者为教程编纂组的成员Matthijs Hollemans. 2014/12/10更新:  ...

  5. 【转】iOS 9 Storyboard 教程(一上)

    转自:http://blog.csdn.net/yangmeng13930719363/article/details/49886547 Storyboard是在iOS5之后新增的一个令人兴奋的功能, ...

  6. [Swift]UIAlertController 以及 Swift 中的闭包和枚举

    原文地址:http://blog.callmewhy.com/2014/10/08/uialertcontroller-swift-closures-enum/ 在 iOS8 的 SDK 中, UIK ...

  7. Storyboard 全解析

    XCode 4.3.2 新功能 - Storyboard 最近开始比较有空在玩 XCode 4.3.2,赫然发现它多了个 Storyboard 的东东. Storyboard 这个东西一般来说是在做创 ...

  8. 使用Storyboard拖线容易出错的地方

    使用Storyboard拖线容易出错的地方: 在Storyboard中,选中某个控件,按住ctrl键进行拖线,建立Outlet和Action后,不能手动再去修改自动生成的代码,然后再次进行连线,这样会 ...

  9. 浅谈iOS 5的StoryBoard

    转自:http://blog.163.com/wangy_0223/blog/static/450146612012318113233218/ 示例代码的Github地址:https://github ...

随机推荐

  1. 3/16 Django框架 环境搭建

    3/16 Django框架 环境搭建 环境搭建 Python解释器 Python代码通过Python解释器去执行. 编程语言 机器语言---汇编语言(助记符)---高级语言 解释型语言:解释器将代码一 ...

  2. 小米开源文件管理器MiCodeFileExplorer-源码研究(5)-AsyncTask异步任务

    说明:本文的文字和代码,主要来自于网上的2篇文章. 第4篇的时候,提到了异步任务AsyncTask. 网上找了2篇文章学习下,copy网友的代码,稍微改了几个字,运行成功了. 在开发Android移动 ...

  3. HDU——T 2594 Simpsons’ Hidden Talents

    http://acm.hdu.edu.cn/showproblem.php?pid=2594 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  4. ios UITextView 提示文本

    定义两个UITextView,一个用于输入文本,一个用于显示提示信息,当输入文本为空时显示提示信息,否则不显示提示信息. //6.3.1文字内容提示 _contentTextViewTip = [[U ...

  5. Qt样式表之盒子模型(以QSS来讲解,而不是CSS)

    说起样式表,不得不提的就是盒子模型了,今天小豆君就来给大家介绍下盒子模型. 上图是一张盒子模型图. 对于一个窗口,其包括四个矩形边框.以中间的边框矩形(border)为基准,在border外侧的是外边 ...

  6. 8 Great Java 8 Features No One's Talking about--转载

    原文地址:http://www.infoq.com/articles/Java-8-Quiet-Features If you haven’t seen some of the videos or t ...

  7. 洛谷P2660 zzc 种田

    题目背景 可能以后 zzc就去种田了. 题目描述 田地是一个巨大的矩形,然而zzc 每次只能种一个正方形,而每种一个正方形时zzc所花的体力值是正方形的周长,种过的田不可以再种,zzc很懒还要节约体力 ...

  8. Maven学习笔记4

    POM解析pom描述自身坐标,以及它关联的依赖,插件,仓库等. 项目模块设计项目聚合和继承. pom标签解析1. pom标签解析2. pom标签解析3. pom标签解析4. 聚合和继承 聚合模块只保留 ...

  9. STM32W108无线射频模块串行通信接口编程实例

    STM32W108无线射频模块UART通信应用实例 基于STM32W108芯片,编写串口測试程序,測试串口通信.完毕PC通过串口与STM32W108进行通信. 开发环境与硬件平台 硬件:STM32W1 ...

  10. Android Unable to execute dex: method ID not in [0, 0xffff]: 65536 问题解决方法

    开始一个新项目的时候,Build工程的时候一直报这个错误: 控制台报错误:Conversion to Dalvik format failed: Unable to execute dex: meth ...