У меня есть флажок (UIButton) и метка в UITableViewCell. Я хочу изменить текст метки (цвет + зачеркнутый), когда нажимаю на флажок.
Это для приложения рецепта. После того, как готовый шаг сделан, пользователь может «проверить», как это сделано.
Это моя текущая функция cellForRowAt для tableView:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == groceryTableView {
let cell = tableView.dequeueReusableCell(withIdentifier: groceryTableViewCell, for: indexPath) as! GroceryItemTableViewCell
cell.amoutLabel.text = indexPath.item % 2 == 0 ? "50 g" : "500 ml"
cell.itemLabel.text = indexPath.item % 2 == 0 ? "Cheese" : "Milk"
cell.selectionStyle = .none
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: cookingStepTableViewCell, for: indexPath) as! CookingStepTableViewCell
cell.cookingStepDescription.text = indexPath.item % 2 == 0 ? "Test 123..." : "Test 321..."
cell.selectionStyle = .none
cell.delegate = self
return cell
}
}
И это моя функция Button addTarget, которая делегирована из класса TableViewCell фактическому классу ViewController:
func cookingStepDone(description: String, isDone: Bool) {
// if isDone == true
// label textcolor is gray + strikethrough
// if isDone == false
// no change...
}
Я хочу, чтобы метка cell.cookingStepDescription была изменена, если "isDone" имеет значение true (= установите флажок)