Chirag Lukhi
Chirag Lukhi

Reputation: 1546

Method calling via performSelectorOnMainThread Vs Normal method calling

can any one tell me what is different when I call method using performSelectorOnMainThread and calling same method without performSelector.

For Exa.

-(void)sampleCALL{
     ..........
}

NOW Call this method using these two senario:

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

or

[self sampleCALL];

How these two method are getting executed? Please help me to find this concept properly.

Upvotes: 3

Views: 373

Answers (1)

Saad
Saad

Reputation: 8947

in firs one case [self sampleCALL]; your method will be called in the thread where control was at current time. it will maintain all the stack manipulation what it does for method calling from another method.

while

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

calls the method in main thread whatever the controls current thread is. All UI actions are performed in main thread always.

Upvotes: 2

Related Questions