I’m having some trouble figuring out hot to update a UILabel twice in one action. Basically the user hits a play button to hear a sound. While the sound is playing “message 1” appears in the UILabel. When the sound is done playing “Message 2” appears in the same label. When I run this the label goes directly to “message 2”.
.h
@interface ViewController : UIViewController
<AVAudioRecorderDelegate, AVAudioPlayerDelegate>
{
AVAudioPlayer *audioPlayer;
UIButton *playButton;
UILabel *answerLabel;
}
@property (nonatomic, retain) IBOutlet UIButton *playButton;
@property (nonatomic, retain) IBOutlet UILabel *answerLabel;
-(IBAction) play;
@end
.m
-(IBAction) play
{
int length = [audioPlayer duration];
[audioPlayer play];
answerLabel.text = @"Message 1";
[NSThread sleepForTimeInterval:length];
answerLabel.text = @"Message 2";
}
I see you implement the
AVAudioPlayerDelegateprotocol, so I assume that at some point you set the delegate of the player toselfIf that is the case, change your play method to the following:
Then implement this method: