Reputation: 1081
I have to download and parse huge XML files. Downloading the data occurs in an NSOperation which also triggers the NSXMLParser once the download finishes.
Now since I want to give the user the ability to cancel the whole process at anytime, I added a cancel button, which stops the download and cancels the operation.
Now my problem is: Even though my NSOperation runs in the background, the UI gets completely blocked when the NSXMLParser starts parsing. So touching the cancel button is pointless.
How can this happen? Since I am triggering the parser from inside the NSOperation (after finishing the download) I thought parsing should also be performed in the background?!
!!!EDIT!!!: I did a test. I checked the thread the parser runs on. It is the main thread. How can this happen? The NSOperation is started on a background thread, how can the parser be on the main thread? And how can I avoid this?
Upvotes: 1
Views: 264
Reputation: 1081
Solved it. The problem was that NSURLConnection apparently calls its delegate on the main thread, resulting in every following method call to be performed also on the main thread.
So I just had to explicitly take my method call in to the background again.
Upvotes: 1