iT邦幫忙

2025 iThome 鐵人賽

DAY 17
0
Mobile Development

Xcode x Swift Vibe coding進階開發之旅系列 第 17

Xcode x Swift Vibe coding進階開發之旅 第十七天 點名系統(10) 增加已簽到圖示

  • 分享至 

  • xImage
  •  

/images/emoticon/emoticon08.gif

指令

在已經簽到的人員增加一個打勾的圖示

回答

https://ithelp.ithome.com.tw/upload/images/20251001/20168187Y9tnSCfPUu.png

心得

我是沒想到這種簡單的功能AI也會出錯,他沒有增加在簽到完成當下的頁面刷新,導致要切換到其他頁面再回來才會刷新/images/emoticon/emoticon04.gif

人工修改

 private func performCheckIn(for user: User, note: String?) {
  tbvselect.reloadData()
    }

/images/emoticon/emoticon03.gif

程式

// 返回每一行的內容
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "UserCell", for: indexPath)
        
        // 獲取對應的使用者資料
        if let currentUser = users?[indexPath.row] {
            cell.textLabel?.text = "\(currentUser.Name) (\(currentUser.userId))"
            
            // 檢查用戶是否在今天已經簽到
            if let lastCheckInTime = currentUser.lastCheckInTime {
                let calendar = Calendar.current
                let today = calendar.startOfDay(for: Date())
                let checkInDate = calendar.startOfDay(for: lastCheckInTime)
                
                // 如果是今天簽到的,顯示打勾圖示
                if calendar.isDate(today, inSameDayAs: checkInDate) {
                    // 使用系統自帶的打勾圖標
                    cell.accessoryType = .checkmark
                    cell.tintColor = .systemGreen // 使用綠色
                } else {
                    cell.accessoryType = .none
                }
            } else {
                cell.accessoryType = .none
            }
        } else {
            cell.textLabel?.text = "未知使用者"
            cell.accessoryType = .none
        }
        
        return cell
    }

上一篇
Xcode x Swift Vibe coding進階開發之旅 第十六天 點名系統(9) 增加篩選查看簽到紀錄的人員
下一篇
Xcode x Swift Vibe coding進階開發之旅 第十八天 點名系統(11) 增加活動狀態功能
系列文
Xcode x Swift Vibe coding進階開發之旅22
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言