Abdul Samad
Abdul Samad

Reputation: 5918

Performselector not call in NSThread

I have a problem that i want to call a function when one of my functions that is running into a seperate thread comes to an end:

[NSThread detachNewThreadSelector:@selector(fetchFeaturedFreeApps) toTarget:self withObject:nil];

here is my fetchFeaturedFreeApps function

-(void)fetchFeaturedFreeApps
{
    ////all my code
    [self performSelector:@selector(closeView) withObject:nil afterDelay:4.0];
}

My problem is that the close view methods doesnt run after the 4 seconds.

Hoew if i call the fetchFeaturedFreeApps method with perform selector then my closeview metod is called properly.

Your valuable help is highly appreciated.

Upvotes: 0

Views: 616

Answers (1)

Alex Reynolds
Alex Reynolds

Reputation: 96947

You want to run any UI or view update code in a selector that runs on the main thread, not in a background thread. Use -performSelectorOnMainThread:withObject:waitUntilDone: and place a timer in that selector to fire after four seconds, which closes your view.

Upvotes: 3

Related Questions