PDA

View Full Version : NSThread and callBack




sujithkrishnan
May 13, 2009, 01:56 AM
Hi all,

I am having a util class and some method associated with it.

I am calling the someMethod in a detached thread using code shown below




In AppDelegate.m

[NSThread detachNewThreadSelector:@selector(someMethod:) toTarget:utilClassObject withObject:nil];


After the successful completion of thread i want to make a callback to method in AppDelegate class. But the below method (which i am supposed to use) is not having parameter to specify the target.

Below code will look for callBackMethod in utilClass

In utilclass.m
In someMethod
[self performSelectorOnMainThread:@selector(callbackMethod:) withObject:nil waitUntilDone:NO];



kainjow
May 13, 2009, 02:12 AM
performSelectorOnMainThread:withObject:waitUntilDone: is called on the target object where the selector exists, so "self" is the target. Maybe it should be something like:

[delegate performSelectorOnMainThread:@selector(callbackMethod:) withObject:nil waitUntilDone:NO];