I create a new thread from a controller like this:
[NSThread detachNewThreadSelector:@selector(makeMovie) toTarget:movieMaker withObject:nil];
What is the best way to call methods on the controller from the new thread/movieMaker object?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this case, you probably want to use the delegate pattern. In your movie-maker class’s .h file:
…and in its .m:
Then in your controller’s header, declare that it supports the MovieMakerDelegate protocol, like this:
and in your .m, before calling your
-detachNewThreadSelector:etc:, callmovieMaker.delegate = self;. Implement the-movieMaker:didSomething:method on your controller class and you’re good to go.