我在解決一個問題時遇到了一些麻煩,需要一次更新兩次UILabel。基本上用戶點擊播放按鈕來聽到聲音。當聲音播放時,「消息1」出現在UILabel中。當聲音播放完畢後,「Message 2」出現在同一個標籤中。當我運行這個標籤時,會直接轉到「消息2」。以同樣的方法更新UILabel兩次
.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";
}
這個工程,我想我的頭腦變得空白,忽略了audioPlayerDidFinishPlaying部分,不需要[NSThread sleepForTimeInterval:length]部分。 – SNV7