0

i have a search bar and search some information from internet, then start a NSXMLParser from url and then show information parsed in a UITableView, but in this process the UI is blocked, and if i want to cancel the searching to do another search i can't and i have to wait that the parser finish, so my question is how i can perform on another thread if it is the right solution and then abort the searching for doing another search if necessary?...i know the NSOperation class but how this class can then give the information to the table view to display the data?...and how i can abort the operation to do another operation?

now i do this to do the search:

 [self performSelector:@selector(request:) withObject:searchText afterDelay:0.7];

then the request method, start in another class the search with the NSXMLParser...

Piero
  • 9,173
  • 18
  • 90
  • 160

1 Answers1

0

To avoid blocking the UI, you would use

[self performSelectorInBackground:@selector(request:) withObject:text];

I haven't worked much with NSOperation, but from the docs, it looks like you can set a completion block for the operation, in which you could call something like

[self performSelectorOnMainThread:@selector(populateMyTable) withObject:nil waitUntilDone:NO];

Also, NSOperation has an instance method cancel that seems to offer what you're looking for as far as aborting your search method.

geraldWilliam
  • 4,123
  • 1
  • 23
  • 35