Gavin
Gavin

Reputation: 2824

Stop current NSURLConnection

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?

Upvotes: 13

Views: 11154

Answers (2)

kjiyoung
kjiyoung

Reputation: 218

You could try to use asynchronous request. A good library for such call is ASIHTTPRequest.

set [request cancel]; whenever you need to make another new request.

Upvotes: 0

Filip Radelic
Filip Radelic

Reputation: 26683

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

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

Upvotes: 27

Related Questions