Как отображать UITextLabels как (галочка) в ячейке при нажатии UITableViewCell? - PullRequest
1 голос
/ 04 мая 2020

Я работаю над UITableView, который действует как контрольный список. Мне удалось отобразить UITextLabel, когда UITableViewCell коснулся, и скрыть UITextLabel, как (Галочка), когда UITableViewCell снова коснулся.

Когда я закрываю приложение, он отображает UITextLabel до прикосновения.

Сделал скриншоты приложения :

enter image description here enter image description here

Теперь у меня есть код, который делает эту работу:

// 1

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "CategoryCell", for: indexPath)
    let category = categories[indexPath.row]


    // cell.secondTextLabelType = hide/display
    if category.done {
        cell.textLabel?.text = category.name
    } else {
        cell.textLabel?.text = ""
    }


    return cell
}

// 2
//hide and display the TextField2
func setItemStatus(item:Category) {
    let status = item.done ? false : true

    item.done = status

}
// 3
//MARK - TableView Delegate Methods

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    //categories goes here
    let item = categories[indexPath.row]

    //cell?.twoItems = hide/display
    setItemStatus(item: item)
    tableView.reloadData()

    saveCategories()

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...