Domanda

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];
    }
}
È stato utile?

Soluzione

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];
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top