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. 【2017 Multi-University Training Contest - Team 5】Rikka with Subset

    [Link]: [Description] 给你a数组的n个数的所有2^n个子集的2^n个子集元素的和; 子集元素的和最大为m; 告诉你各个子集元素的和出现的次数; 如 1 2 则0出现1次,1出现1 ...

  2. Java中join和yield的作用

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 1.   A.join,在API中的解释是,堵塞当前线程B,直到A执行完毕并死掉,再执行B. 用一个 ...

  3. 洛谷——P1843 奶牛晒衣服

    https://www.luogu.org/problem/show?pid=1843#sub 题目背景 熊大妈决定给每个牛宝宝都穿上可爱的婴儿装 . 于是 , 为牛宝宝洗晒衣 服就成了很不爽的事情. ...

  4. View_01_LayoutInflater的原理、使用方法

    View_01_LayoutInflater的原理.使用方法 本篇博客是郭神博客Android视图状态及重绘流程分析,带你一步步深入了解View(一)的读书笔记的笔记. LayoutInflater简 ...

  5. IOS经常使用的性能优化策略

    1.用ARC管理内存 2.对于UITableView使用重用机制 3.UIView及其子类设置opaque=true 4.主进程是用来绘制UI的,所以不要堵塞 5.慎用XIB,由于XIB创建UIVie ...

  6. lighttpd启动不了,libssl.so.4&amp;libcrypto.so.4 缺失

    lighttd的出错日志在 log/out_lighttpd 里,当lighttd启动不了时候,这里文件中会说明原因. 今天的报错是 error while loading shared librar ...

  7. Windows简单入门-送给第一次使用电脑的朋友

    序言 写本篇文章前.不得不说我已经好久没有写博客了,快接近3个月了 吧,本来去年说參加今年的博客之星的,结果这都立即结束了:不得不说对自己有些嘲讽. 本篇文章是纯小白文章.之所以写这个是由于前段时间妹 ...

  8. ELK之日志查询、收集与分析系统

    项目由来 (1)开发人员不能登录线上服务器查看详细日志,经过运维周转费时费力 (2)日志数据分散在多个系统,难以查找与整合 (3)日志数据量巨大,查询速度太慢,无法满足需求 (4)无法全局掌控项目运行 ...

  9. 使用STS新的工作空间无需再配置

    在你的新的工作空间中找到比如 F:\java-wokespace\你的新的工作空间名称\.metadata\.plugins\org.eclipse.core.runtime\.settings 找到 ...

  10. File Upload with Jersey

    package com.toic.rest; import java.io.File; import java.io.FileOutputStream; import java.io.IOExcept ...