jianhua
jianhua

Reputation: 1011

Strange, IPhone performSelector on sub-thread doesn't work.

I want to do some action on a thread using the following API, so strange selector poiOneBoxSearch hasn't been invoked, why? Any mistake on the code? Thanks.

- (void)poiOneBoxSearch{
     [self poiOneBoxSearcWithQueryString:@"coffee" isFinished:YES];
}

- (void)test1{
     NSThread* thread = [[NSThread alloc] init];
     [self performSelector:@selector(poiOneBoxSearch)
               onThread:thread
             withObject:nil
          waitUntilDone:YES];
     [thread release];
}

Upvotes: 1

Views: 1186

Answers (3)

Anil Kothari
Anil Kothari

Reputation: 7733

[self performSelectorInBackground:@selector(poiOneBoxSearch) withObject:nil];

- (void) poiOneBoxSearch{
          @autoreleasepool { 
     [self poiOneBoxSearcWithQueryString:@"coffee" isFinished:YES];
} }

The most important thing that you have to keep in mind is that since this method creates a thread on the given selector, the selector must have an autorelease pool just like any other thread in a reference-counted memory environment.

Upvotes: 0

Mohammad Kamar Shad
Mohammad Kamar Shad

Reputation: 6067

If You want use performSelector Method You should Read below Link ,I Think You missed SOmething

Please Goes Through This Link

If Not you may Use Below Code.

Try This

 - (void)test1{
[NSThread detachNewThreadSelector:@selector(poiOneBoxSearch) toTarget:self withObject:nil];
 }

Upvotes: 2

Michael Frederick
Michael Frederick

Reputation: 16714

Try this:

[self performSelectorInBackground:@selector(poiOneBoxSearch) withObject:nil waitUntilDone:YES];

Upvotes: 0

Related Questions