Answer the question
In order to leave comments, you need to log in
Execute function from another cell in UIcollectionView?
there is a collection in it two cells are customized differently.
In one cell there is a button on pressing of which the label text of another cell should change.
Why is it that when I click on 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"
}
}
Answer the question
In order to leave comments, you need to log in
Different cells in the same collection.
The controller in which the collection view is held to make a delegate method that will twitch from the first cell when a button is pressed on it, in this method, for example, the second cell with the desired parameter will be reloaded.
I would make a variable in the controller responsible for the text in the second cell. And I changed it in the delegate method, then reloaded collectionview.
If you have only two cells and you know 100% which one you need, then you can get this cell from the cell array of the table at the desired index
. Example:
let indexPath = NSIndexPath(row:1 section:0)
if let cell = tableView.cellForRow( at: indexPath) as? customCell {
cell?.label.text = "123"
}
In one cell there is a button on pressing of which the label text of another cell should change.And how does the first cell get the second one? Maybe the variable which should contain a reference to the second cell is empty? Checked?
Why is it that when I click on the button nothing changes?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question