簡體   English   中英

如何在 reloadData() 后為 UITableViewCell 內的 UILabel 設置動畫?

[英]How do I animate a UILabel inside a UITableViewCell after reloadData()?

我正在創建一個表單,每當用戶忘記填寫表單字段時,我都有一種機制來突出顯示用戶未在其中選擇值的任何單元格所需的文本標簽。在顏色更改反映后並且重新加載了 tableView,我還想為突出顯示的標簽設置動畫。 實現這一目標的正確方法是什么? tableView 可以加載自定義 tableViewCells 的混合,所以我想知道這可以在所有自定義單元格中完成。

請注意:如果點擊“提交”按鈕,標簽會以紅色突出顯示。 隨着缺失的字段被填寫,標簽一旦分配給該字段的值就不再突出顯示。 所以現在我需要一種方法來為不同自定義單元格類的單元格上的各個標簽設置動畫,僅當用戶嘗試單擊缺少字段的提交按鈕時

Protocols

您可以創建自定義單元格將實現的協議,因此在每個自定義單元格中,您可以自己實現一個函數,您將在表視圖的委托方法中調用該函數:

     tableView(_ tableView: UITableView, 
                willDisplay cell: UITableViewCell, 
                   forRowAt indexPath: IndexPath) {

      guard let customCellThatImplementsFormCell = cell as? FormCell else { return }

/// check if has errors and call either function 

}

取決於您的單元格是否有錯誤

這是一個非常簡單的想法,但它可能看起來像這樣

protocol FormCell {
 func showError()
 func hideError()
}


class FormTextInputCell: UITableViewCell {

}

extension FormTextInputCell: FormCell {

  func showError() {
    // Style the cell and animate what you want
 }

 func hideError() {
    // Style the cell and animate what you want
 }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM