F
F
FlooDwm2016-11-24 16:25:48
iOS
FlooDwm, 2016-11-24 16:25:48

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

3 answer(s)
P
PacifiK, 2016-11-25
@PacifiK

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.

M
Maxim Globak, 2016-11-26
@maximglobak

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"
}

B
briahas, 2016-11-28
@briahas

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?
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?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question