2017-07-08 141 views
-2

我有一個包含標籤和圖像的單元格。當用戶點擊View Controller頂部的編輯按鈕時,我希望單元格內的圖像出現,再次單擊編輯按鈕時,圖像應該隱藏。單擊按鈕時隱藏UItableview單元格內的圖像

最接近的例子是iPhone中的電子郵件單元格。當我點擊編輯按鈕時,每封電子郵件旁邊都有一個複選框,當我點擊取消時,檢查消失。

謝謝

+2

請提供一些代碼或東西,你已經嘗試過。 – Eric

+0

你可以使用'.isHidden'屬性,每個'UIView'子類都有。只需將其設置爲「true」即可。 – Marmelador

回答

2

一些簡單的方法來開始是創建一些財產isImageDisplaying這將表明您的視圖控制器的當前狀態。當用戶點擊按鈕時,您只需更改此var的狀態並重新加載您的表格視圖。在這裏你可以找到一些樣品溶液:

var isImageDisplaying: Bool = false { 
    didSet { 
     tableView.reloadData() 
    } 
} 

@IBAction func editButtonDidClick(_ sender: UIBarButtonItem) { 
    isImageDisplaying = !isImageDisplaying 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = ... // get cell 
    cell.imageView.isHidden = !isImageDisplaying 
    // configure rest of the cell 
    return cell 
} 
相關問題