F
F
FlooDwm2016-11-25 12:43:11
iOS
FlooDwm, 2016-11-25 12:43:11

How can I change the text of the second label as well?

Class BaseCell : UICollectionViewCell{
        //button
        //label1
        //label2
        //foo() {download data and change label1 & label2 text}
        //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)
}

There is a collection in it some cells. In the first cell, a button and label1 are added. In the second cell label2. There is a function that uploads data and changes the values ​​of the labels. there is a button on pressing on which the text of all labels should change. When I press the text of label1 changes, but the text of label2 does not change. If I remove the button from cell1 and insert it into cell 2, then the text of label2 changes but the text of label1 does not change. How to fix that would change the text of both labels

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Globak, 2016-11-26
@maximglobak

`tableView.reloadData()`
You need to update the entire table, so you need to call a function that updates all cells.
You can also update all cells with animation
`- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
`
I don’t remember how it will be in swift.

B
briahas, 2016-11-28
@briahas

For good:
- someone else should change the texts in the cells, not the cells. The cell only displays the information that comes to it.
So:
- the functions processing the data upload and pressing should be in some controller
- which, after processing the information, will update the models
- and after that it will say the collectionView - "Update"
- ... or update specific cells ... This is how it should be.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question