参考链接:https://github.com/soapyigu/Swift-30-Projects

 1 import UIKit
 2
 3 class Product: NSObject {
 4     var name: String?
 5     var cellImageName: String?
 6     var fullscreenImageName: String?
 7
 8     init(name: String, cellImageName: String, fullscreenImageName: String) {
 9         self.name = name
10         self.cellImageName = cellImageName
11         self.fullscreenImageName = fullscreenImageName
12     }
13 }

  1 import UIKit
  2
  3 class ProductsTableViewController: UITableViewController {
  4
  5     fileprivate var products: [Product]?
  6     fileprivate let identifier = "productCell"
  7
  8     override func viewDidLoad() {
  9         super.viewDidLoad()
 10
 11         // Uncomment the following line to preserve selection between presentations
 12         // self.clearsSelectionOnViewWillAppear = false
 13
 14         // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
 15         // self.navigationItem.rightBarButtonItem = self.editButtonItem
 16
 17         products = [
 18             Product.init(name: "1907 Wall Set", cellImageName: "image-cell1", fullscreenImageName: "phone-fullscreen1"),
 19             Product.init(name: "1921 Dial Phone", cellImageName: "image-cell2", fullscreenImageName: "phone-fullscreen2"),
 20             Product.init(name: "1937 Desk Set", cellImageName: "image-cell3", fullscreenImageName: "phone-fullscreen3"),
 21             Product.init(name: "1984 Moto Portable", cellImageName: "image-cell4", fullscreenImageName: "phone-fullscreen4")
 22         ]
 23     }
 24
 25     override func didReceiveMemoryWarning() {
 26         super.didReceiveMemoryWarning()
 27         // Dispose of any resources that can be recreated.
 28     }
 29
 30     // MARK: - Table view data source
 31
 32     override func numberOfSections(in tableView: UITableView) -> Int {
 33         // #warning Incomplete implementation, return the number of sections
 34         return 1
 35     }
 36
 37     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 38         // #warning Incomplete implementation, return the number of rows
 39         return products?.count ?? 0
 40     }
 41
 42     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 43         let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)
 44
 45         guard let products = products else { return cell }
 46
 47         // Configure the cell...
 48         cell.textLabel?.text = products[(indexPath as NSIndexPath).row].name
 49
 50         if let imageName = products[(indexPath as NSIndexPath).row].cellImageName {
 51             cell.imageView?.image = UIImage.init(named: imageName)
 52         }
 53
 54         return cell
 55     }
 56
 57     /*
 58     // Override to support conditional editing of the table view.
 59     override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
 60         // Return false if you do not want the specified item to be editable.
 61         return true
 62     }
 63     */
 64
 65     /*
 66     // Override to support editing the table view.
 67     override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
 68         if editingStyle == .delete {
 69             // Delete the row from the data source
 70             tableView.deleteRows(at: [indexPath], with: .fade)
 71         } else if editingStyle == .insert {
 72             // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 73         }
 74     }
 75     */
 76
 77     /*
 78     // Override to support rearranging the table view.
 79     override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
 80
 81     }
 82     */
 83
 84     /*
 85     // Override to support conditional rearranging of the table view.
 86     override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
 87         // Return false if you do not want the item to be re-orderable.
 88         return true
 89     }
 90     */
 91
 92
 93     // MARK: - Navigation
 94
 95     // In a storyboard-based application, you will often want to do a little preparation before navigation
 96     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
 97         // Get the new view controller using segue.destinationViewController.
 98         // Pass the selected object to the new view controller.
 99         if segue.identifier == "showProduct" {
100             if let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell), let productVC = segue.destination as? ProductViewController {
101                 productVC.product = products?[(indexPath as NSIndexPath).row]
102             }
103         }
104     }
105
106
107 }

 1 import UIKit
 2
 3 class ProductViewController: UIViewController {
 4
 5     @IBOutlet var productImageView: UIImageView!
 6     @IBOutlet var productNameLabel: UILabel!
 7
 8     var product: Product?
 9
10     override func viewDidLoad() {
11         super.viewDidLoad()
12
13         // Do any additional setup after loading the view.
14
15         productNameLabel.text = product?.name
16
17         if let imageName = product?.fullscreenImageName {
18             productImageView.image = UIImage.init(named: imageName)
19         }
20     }
21
22     @IBAction func addToCartButtonDidTap(_ sender: AnyObject) {
23         print("Add to cart successfully")
24     }
25
26     override func didReceiveMemoryWarning() {
27         super.didReceiveMemoryWarning()
28         // Dispose of any resources that can be recreated.
29     }
30
31
32     /*
33     // MARK: - Navigation
34
35     // In a storyboard-based application, you will often want to do a little preparation before navigation
36     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
37         // Get the new view controller using segue.destinationViewController.
38         // Pass the selected object to the new view controller.
39     }
40     */
41
42 }

转载于:https://www.cnblogs.com/chmhml/p/8473133.html

第十天:SwiftGoodAsOldPhones相关推荐

  1. 系统规划与管理备考整理

    @ 一.信息系统综合知识 1.1 信息的定义和属性 1.信息是客观事物状态和运动特征的一种普遍相识,客观世界中大量存在.产生和传递着以这些方式表示出各种各样的信息 (1)信息的定性描述 控制论的创始人 ...

  2. 十大算法,描述+代码+演示+分析+改进(赶紧收藏!)

    十大算法 1.冒泡排序 ​ (1)算法描述 ​ 冒泡排序是一种简单的排序算法.它重复地走访过要排序的数列,一次比较两个元素,如果它们的顺序错误就把它们交换过来.走访数列的工作是重复地进行直到没有再需要 ...

  3. 预见未来丨机器学习:未来十年研究热点

    <h2 class="subheader">机器学习:未来十年研究热点 </h2><div class="gray-d1-c margin- ...

  4. 第十六节,使用函数封装库tf.contrib.layers

    目录 一 tf.contrib.layers中的具体函数介绍 1.tf.contrib.layers.conv2d()函数的定义如下: 2.tf.contrib.layers.max_pool2d() ...

  5. 新十年嵌入式音频的五大趋势

    新十年嵌入式音频的五大趋势 Five embedded audio trends for the new decade 很难相信正在进入一个新的十年.十年前,像Alexa这样的语音技术甚至还没有成为现 ...

  6. 2021年大数据Kafka(十二):❤️Kafka配额限速机制❤️

    全网最详细的大数据Kafka文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 系列历史文章 Kafka配额限速机制 限制producer端的速率 限制c ...

  7. 2021年大数据Kafka(十):kafka生产者数据分发策略

    全网最详细的大数据Kafka文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 系列历史文章 生产者数据分发策略 策略一:用户指定了partition 策 ...

  8. 2021年大数据HBase(十六):HBase的协处理器(Coprocessor)

    全网最详细的大数据HBase文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 系列历史文章 HBase的协处理器(Coprocessor) 一.起源 二 ...

  9. 2021年大数据HBase(十五):HBase的Bulk Load批量加载操作

    全网最详细的大数据HBase文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 系列历史文章 HBase的Bulk Load批量加载操作 一.Bulk L ...

最新文章

  1. 告警系统邮件引擎、运行告警系统
  2. poj 1298 The Hardest Problem Ever
  3. CentOS6.7安装SBT
  4. 服务稳定性及应用防护方案
  5. .NET Core + K8S + Apollo 玩转配置中心
  6. strace命令(收集整理,常看常新)
  7. linux screen会话命令
  8. shell 脚本里面的数组和遍历
  9. 使用SaveAsPDFandXPS + jacob实现Java word转pdf(开发笔记)
  10. Prometheus客户端docker监控cAdvisor
  11. VBox虚拟机在注册过程中可能报的错(一条龙服务) 打开虚拟文件失败、relaunching VirtualBox VM process 5 (Solved)等等
  12. 百度富文本编辑器上传图片到oss的步骤
  13. 有吧友需要PDF的下载站点,好吧,我这边汇总一下
  14. Android之QQ登录
  15. 微信小程序--红色星球
  16. 视频直播制作软件:MimoLive Mac v5.2b2
  17. html标题如何设置行书,六个小招数,让你的行书不再俗气!
  18. C++数组去重与排序
  19. IOS 跨域问题分析和处理
  20. Goahead嵌入式linux移植资料整理

热门文章

  1. P1028 [NOIP2001 普及组] 数的计算 python
  2. ESP32 + ESP-IDF |GPIO 01 - 驱动外部两个LED灯,以每300ms的时间间隔闪烁
  3. python大作业爬虫_爬虫大作业
  4. BootStrap笔记-信息提示框的使用
  5. Java笔记-spring-rabbit框架中消息中header的添加
  6. C++设计模式-状态模式
  7. Arduino笔记-呼吸流水灯
  8. STL学习笔记-multimap的基本使用
  9. 7.3图的遍历(深度优先)-理论
  10. 计算机技能大赛试题及答案,全国中职计算机技能大赛(园区网)试题及参考答案...