-2

What is the logic i should follow to integrate a like button in a tableview cell?

How do you update a text label inside the cell signaling how many likes it has in real time IE: when you click the like button it either adds a like or removes a like?

The button also is highlighted when current_like = true and not highlighted when current_like = false

Where do I update that kind of stuff?

How can you update a cells label and display the new label from within the cell? or is it NECESSARY to reload cell for row at Index Path?

2 Answers2

1

The two main problems/steps you have to achieve are: - Update the label with the new like - Update the datasource of the table to keep the data persistent.

So, what I would make:

Set your custom UITableViewCell as target for the Button, so the cell can know when the button was clicked. In the target function/selector you should update the label.

Now, you have to inform the datasource of your table that the cell has a new like. You can create a protocol in UITableViewCell and set the TableDataSource as its delegate. Then, when the button was clicked you can notify the delegate.

You can achieve the same behavior with NSNotificationCenter, instead delegation.

Regards ;)

crom87
  • 1,141
  • 9
  • 18
0

To change the cell's content without reloading you need to create a pointer to that cell. You can change your cell's parameters directly using a pointer without reloading cell. So it would be something like

self.myCell.label.text = something

And to assign the pointer to your cell you must put something like this in your cell adding method:

self.myCell = yourLikeCounterCell
Warr1on
  • 1
  • 2