"I have an NSURLConnection in a subclass of a tableview cell" - never do this. As Sung-Pil Lim already pointed out, TableView cells will be reused, which can cause this problem.
In any case, the response data of your connection is a property of the model. A model can encapsulate how it gets to this data. If this data is not available immediately after it is accessed, it should specify the value "placeholder" instead and run an asynchronous task that retrieves this data.
Suppose a model property, an image, is available to the view controller so that it is displayed in the view. The model has not yet uploaded its actual image - and thus it returns a “placeholder image” to allow the display of something. But at the same time, the model launches an asynchronous task to load the image. When this connection finishes loading data, the model updates the internal property, thereby replacing the placeholder with a real image. Property updating should be done in the main thread - because UIKit views can access the same property.
During initialization, the view controller is registered as an observer of the model property (see KVO). When the model property is updated, the controller receives a notification. Then, the view controller takes appropriate action so that the view is redrawn and displays the new updated value.
Your model should have a “cancel” method, which will be sent to the model from the controller when the actual value of the model property is no longer required. For example, the user switched to another view (see ViewWillDisappear).
source share