سؤال

I am making a generic function to handle the stopping and starting of different media types in C4. I tried the following method to be called but it seems that the play method conflicts with the play method in the AVPlayer play method when called in this way. Is there a way to solve this problem?

-(void) StartStop: (NSNotification *) notification
{
    if( [[notification object] isKindOfClass:[C4Movie class]] )
    {
        if( [[notification object] isPlaying])
            [[notification object] pause];
        else
            [[notification object] play];
    }
}
هل كانت مفيدة؟

المحلول

The solution is to cast the notifying object into the specific class so that the compiler knows which object to call. Objective-C uses dynamic binding. See this question for a detailed explanation: Late Binding vs Dynamic Binding

-(void) StartStop: (NSNotification *) notification
{
    if( [[notification object] isKindOfClass:[C4Movie class]] )
    {
        C4Movie * temp = [notification object];
        if( [temp isPlaying])
            [temp pause];
        else
            [temp play];
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top