views:

288

answers:

2

I have a button class - when the button is clicked, the playFile method of the MyAudio class is called. So my question is, its trivial to call the playFile method from the button class, but how do I call the method displayStopButton from the initiator class?

button class

- (void)myButtonClicked: (id)sender
{
    [MyAudio playFile];

}

-(void)enablePlayButton
{
  // test
}


MyAudio class

-(BOOL)playFile{

   // Init AVAudioPlayer
}

- (void)audioPlayerDidFinishPlaying: (AVAudioPlayer*)player successfully: (BOOL)flag
{

   // make a call back to calling class????

}
A: 

You have to keep a pointer you all the controls you want to enable and disable in the controller. Using these handles you can turn them on and off as you get notificaitons fro the Audio sub-system.

Roger Nolan
+1  A: 

What you are calling your Button class looks like your controller class. The audioPlayerDidFinishPlaying sounds like a method that should also be implemented in your controller class. That way, you can set your controller class to be a delegate of the audio player class, and the implementation for the audioPlayerDidFinishPlaying method can make the call to [self displayStopButton].

Nick Stamas