开发者

How to use NSNotification in following scenario (IPhone SDK)?

Considering real life situation, suppose i have assigned some work to 3 people(say Person A, Person B, Person C), instead of waiting for them to complete a task each, i want that when each Person completes all assigned tasks, he/she will notify me distinctly. So that i can take further decision based on his/her task.

I want to implement this situation in code, with out using separate thread and delegates, i mean using NSNotification.

How can i do this stuff with progra开发者_JS百科mming, can u solve above situation using code (iPhone SDK-Objective C)?


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer.moviePlayer];


- (void)myMovieFinishedCallback:(NSNotification*)aNotification
{    
    // Release the movie instance created in playMovieAtURL

    MPMoviePlayerController *theMovie = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:theMovie];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIDeviceOrientationDidChangeNotification
                                                  object:theMovie]; 

    [theMovie stop];
    [theMovie.view removeFromSuperview];

} 

Like this you can use the NSNotification. Hope you understand.


As long as you are not using separate threads (or some kind of simulated asynchronicity) the 3 persons will need to wait on each other and using notifications doesn't really make sense.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜