Ankit Sachan
Ankit Sachan

Reputation: 7840

UItableViewCell: Remove observer

Please help me to resolve this I have implemented KVO on my uitableviewCell

1) My cells are observing some attributes of model object. 2) Caveat is due to cell reuse single model object is observed by multiple cells.

question is:

1) How can I remove all observers of that model object

or

2) What should I do to remove my cell as observer.

Thanks in advance

Ankit

Upvotes: 1

Views: 1251

Answers (1)

Cocoadelica
Cocoadelica

Reputation: 3026

Probably a bad call to have individual cells observing the model. The point of the UITableViewDataSource protocol is to give you a place to handle changes in the model without tying it directly to the view components. Cells can be dequeued (effectively removed) and dequeued dynamically by the tableview.

If you set up a separate object as the tableview's datasource and to receive notifications of change from the model then you can decouple your model from your view.

This is essentially the Model > View > Controller trinity we are intended to write our code in the image of. Remove the dependency between your UI and the model by putting a controller object in the middle.

Read the guide for better explanation and guidance on this.

If this answer doesn't help the exact problem could you expand on the issue you're having?

Upvotes: 1

Related Questions