D34 - 用 Swift 和公开资讯,打造投资理财的 Apps { 台股申购功能扩充.5 }

原来在 Storyboard 上的 申购 tableViewCell,只有四个 UILabel,现在扩充第五个 UILabel,先将他命名为 fifthSectionLabel。这个 UILabel 装载的资讯,就是价差百分比。显示的格式如 11.22% 这样的格式。

先将 UILabel 在 storyboard 上拉好。

https://ithelp.ithome.com.tw/upload/images/20211013/20140622XVnYLuPlwV.png

然後在 ViewController 中的 cellForRowAt(:) 中,呼叫 model,得到价差百分比 String。如果有得到 String,就显示在 fifthSectionLabel,如果 String 为 nil,则显示 -%

所以扩充後的 cellForRowAt 如下

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        guard let cell = tableView.dequeueReusableCell(withIdentifier: StockSubscriptionTableViewCell.identifier, for: indexPath) as? StockSubscriptionTableViewCell,
              let info = model.getSubscriptionInfo(at: indexPath) else {
            return UITableViewCell()
        }
        
        let state = "申购状态"
        let firstSection = "\(info.stockName) - (\(info.stockCode))"
        let secondSection = "申购股数: \(info.stockCountString)"
        let thirdSection = "申购价: \(info.actualPrice)"
        let forthSection = "中签率: \(info.subscriptionRateString) %"
        
        let fifthSection: String
        if let percentageDiffString = model.getPricePercentDifferenctString(subscription: info) {
            fifthSection = "价差: \(percentageDiffString) % "
        } else {
            fifthSection = "价差: -- % "
        }
        
        cell.stateLabel.text = state
        cell.firstSectionLabel.text = firstSection
        cell.secondSectionLabel.text = secondSection
        cell.thirdSectionLabel.text = thirdSection
        cell.forthSectionLabel.text = forthSection
        cell.fifthSectionLabel.text = fifthSection
        
        modify(cell, with: info)
        
        return cell
    }

完成後的 UI 就如下,就可以知道价差了。建议找价差百分比高的申购,如果真的抽中了,赚的机率比较高,因为申购不一定会赚。

https://ithelp.ithome.com.tw/upload/images/20211013/20140622RqhZZaHwBk.png

台股申购日历
IT铁人赛Demo App

下方是这次 D1 ~ D12 的完成品,可以下载来试
App Store - 台股申购日历

https://ithelp.ithome.com.tw/upload/images/20210924/20140622ypOBM0tgrZ.png


<<:  Day29 Session 的使用-2

>>:  企划实现(29)

【Day 30】总结

这 30 天我们整理了许多 Python 的基本语法,包括了基本的输入输出、if 判断式、while...

Node-RED学习心得(安装篇)

架构图 简介 Node-RED是基於Node.js建构的web浏览器可视化模块开发工具,所以不需要熟...

Day 29 - BFS

大家好,我是长风青云。今天是铁人赛的29天。这是我最後一个要讲的演算法喔。 如果明天的部分不想看不想...

DAY07_终於要来资产搬点啦~啊~不是~是盘点XDDD" 搬点是要搬家是吗~

前言依旧被吃了~跟月饼一样(虽然明天才是中秋节XD) ▉前导观念~先理解这两个数值是怎麽评分的~ (...

Day24:检查登入人数

国庆连假中,假日只想耍废玩 game,不想进修QQ,但为了避免断赛,还是加减推一些东西,等明後天再来...