In the Xcode project, I have 2 classes say ParentViewController and another class ChildViewController which is the sub class of ParentViewController. In ParentViewController class we use NSURLConnection, didReceiveData and connectionDidFinishLoading to fetch some data from back end server. It works perfectly fine. Now in my ChildViewController I need to make connection and fetch data from backend as well. But if I add didReceiveData and connectionDidFinishLoading in ChildViewController, then the didReceiveData in ParentViewController seems doesn’t work anymore. I am wondering why?
Also seems I have a lot of different requests send to backend, so my didReceiveData and connectionDidFinishLoading are overwhelminged with (connect == someConnection) statements. I am wondering any neat way to handle this situation? Thanks.
The subclass will inherit the ParentViewController’s connection delegate methods. If you want the same behavior in the subclass, just don’t implement the delegate methods there.
Another idea is to avoid the delegate methods altogether. In iOS5, the NSURLConnection provides a better way to start a connection using a block for completion, so your code for each connection can be located in context, as follows:
I agree with the other answers that you might want to rethink the design if the app is doing a lot of remote requests.