I am having a hard time understanding this:
__block __weak MyCell *weakSelf = self;
[NetworkManager profileImageForUser:id success ^(UIImage *image, NSString *userId){
weakSelf.leftImageView.image = image;
}];
The issue is that when MyCell is deallocated and then the success block is initiated, then it crashes saying unrecognized selector sent to instance. How do I deal with this?
The reason this crash is happening is that weakSelf is not being retained by the block, which is probably executed asynchronously after the deallocation of the object.
Why are you using __block here? This is the cause of your problem.
__block is only necessary when you are going to MODIFY the object in question from inside the block. __block also prevents the behaviour of the block retaining the object. Since you are not changing the VALUE of weakSelf (only it’s properties), you should not use __block so that the block will retain the object and thus have it in memory when it is required, preventing this crash.