Reputation: 7264
For example, There are 3 sequencial view controllers, A, B, C, in the navigation stack. After sending an async network request in view controller C in the background thread, User may go back to B or A.
What is the best way to handle the network response no matter where the current view controller is?
Thanks.
Upvotes: 2
Views: 338
Reputation: 1648
Since the three view controllers may be interested in the response, don't make it in any of them. Create a class, let's say NetworkHandler
with method - (void) makeRequest
. You can make it a singleton or add it to the AppDelegate
.
In C, call this method.
When - (void) makeRequest
finishes the call, make an NSNotification
and make all three view controllers register to this notification.
Upvotes: 7
Reputation: 637
It is better to have a Singleton class. You can have some delegate also to notify the controller that response received and do the respective action.
Upvotes: 1