Stop current NSURLConnection

Gavin picture Gavin · Aug 29, 2011 · Viewed 11k times · Source

Currently, I am making an NSURLConnection whenever mySearchBar.text did change. I am experiencing an issue whereby if the user enters text too quickly, The respondData gets corrupted.

So, I was wondering is there a way to check whether the same NSURLConnection is still loading? If yes, How do I drop the current connection and start a new one?

Answer

Filip Radelic picture Filip Radelic · Aug 29, 2011

Add a property for that NSURLConnection and before starting new connection, do:

[self.conn cancel];
self.conn = nil;