MEURSAULT
MEURSAULT

Reputation: 8829

Performing App Delegate method on main thread from secondary thread

I have a Iphone app with 2 threads. One is listening to the server, and the other is doing UIKit, OpenGl stuff.

I need to run a method that updates a view from the secondary thread thats listening to a server on the main thread that handles the views so I used

performSelectorOnMainThread:@selector"createGuessingView" withObject:nil waitUntilDone:YES

but for some reason, the method never gets executed. Putting a breakpoint or a printf at the beginning of the method shows that its never invoked. Im really stumped here. Ive used performselectoronmainthread in the same program to update text fields and it worked flawlessly.

edit:

Figured it out :) The problem was that the object that I was using performSelectorOnMainThread was set by this thread before the object was initialized (even allocated) in the main thread. Therefore, the reference was pointing to null, and the selector was not getting recognized.

Thanks for the help

Upvotes: 0

Views: 980

Answers (1)

No one in particular
No one in particular

Reputation: 2672

Shouldn't that be:

@selector(createGuessingView)

with no quotes.

--

EDIT (in response to comment)

What the signature for your method? If it's:

- (void)createGuessingView:(id)something

then you should remember the colon, as in @selector(createGuessingView:)

Upvotes: 2

Related Questions