我在一次操作中两次更新 UILabel 时遇到了一些麻烦。基本上,用户点击播放按钮来听到声音。在播放声音时,UILabel 中出现“message 1”。声音播放完毕后,“Message 2”会出现在同一标签中。当我运行它时,标签直接转到“消息 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";
}