I’m currently asynchronously using NSURLConnection with several UIViews (every view handles NSURLConnection as delegate). The problem I have is when user switches views too fast and the delegate becomes NSZombie the app crashes – that is NSURLConnection doesn’t have living delegate anymore. So, the first question is if there’s a way to circumvent this?
The second question is simple – how do I handle NSZombie? Simple if(myObject != nil).. doesn’t work at all.
You need to cancel the
NSURLConnectionbefore you dispose it’s delegate. Simply keep a reference to the NSURLConnection in yourUIViewthat acts as a delegate and call[urlConnection cancel].After you release a message you need to set your pointer to it to nil if you continue using that pointer. As an example:
Notice however that it is valid to send a message to
nilso you don’t need to safe guard the message sending. It simply won’t have any effect ifmyObject == nil.