There is a collection in it two cells are customized in different ways. In one cell there is a button by pressing which the text of the label of another cell should change. Why then when I press the button nothing changes?

class cell1:UICollectionViewCell{ //button button.addTarget(self, action: #selector(handleChangeDate), for: .touchUpInside) func handleChangeDate(){ cell2.changeLabel() } } class cell2:UICollectionViewCell{ //label func changeLabel(){ self.label.text = "123" } } 
  • When a button is added to the first cell, it changes the text of the label in the first cell but does not change in the third cell and vice versa - maxim rad
  • Class BaseCell : UICollectionViewCell{ //button //label1 //label2 //foo() {download data} //foo2() {change label1 and Label2 text} //button.addTarget(self, action: #selector(foo2), for: .touchUpInside) } class Cell1 : BaseCell { addSubView(label1) addSubView(button) } class Cell2 : BaseCell { addSubView(label1) } - maxim rad
  • Add the code to the question, not to the comment. And in order for something to appear, you need to do a reload. Or a table, or the desired cell. - VAndrJ
  • @VAndrJ why then the text in the first cell changes without reload. Or when I add the button instead of the first cell to the second, the label of the second cell changes, but the text of the label of the first cell does not change. - maxim rad

0