1 回のアクションで UILabel を 2 回更新するホットな方法を見つけるのに苦労しています。基本的に、ユーザーは再生ボタンを押して音を聞きます。サウンドが再生されている間、「メッセージ 1」が UILabel に表示されます。サウンドの再生が完了すると、同じラベルに「メッセージ 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";
}