私のアプリでは、私はオーディオレコーダーを実装しています。すべて正常に動作します。UIAlertViewで時間を表示するには?
しかし、ユーザーが録画ボタンをタップすると、UIAlertView
を秒単位で表示する必要があります。
このように、ユーザーは録音のように簡単に理解できます。
私はこれについて何も考えていません。
どうすればいいですか他のアイデアを教えてください。
私のアプリでは、私はオーディオレコーダーを実装しています。すべて正常に動作します。UIAlertViewで時間を表示するには?
しかし、ユーザーが録画ボタンをタップすると、UIAlertView
を秒単位で表示する必要があります。
このように、ユーザーは録音のように簡単に理解できます。
私はこれについて何も考えていません。
どうすればいいですか他のアイデアを教えてください。
UIAlertViewはiOS 8で廃止されました。アラートのpreferredStyleを使用してUIAlertControllerを使用できるようになりました。
秒はあなたが私はあなたがあなたのyourSecondsVariable
を初期化する(NSDate
の)timeIntervalSinceDate:
を使用することができると思います
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@“Your title string”
message:[NSString stringWithFormat:@“Seconds: %f”,yourSecondsVariable];
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK",nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
を使用することができる静ある場合。
「UIAlertViewはiOS 8で廃止されました。」 –
私は表示されませんこれがどのようにOPの質問に答えるか。これは、アラートコントローラを表示する方法の標準的なスニペットです。質問には「時間の表示方法」が明示されています。時間は動的であり、すべての時間を変化させます。 – norders
時間を動的に(継続的に更新する)したい場合は、この作業を開始する必要があります。
@interface ViewController()
@property (nonatomic, strong) UILabel *timeLabel;
@end
実装:
- (void)timer {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Time" message:@"\n\n\n" preferredStyle:UIAlertControllerStyleAlert];
self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 260, 50)];
self.timeLabel.textAlignment = NSTextAlignmentCenter;
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
self.timeLabel.text = [NSDate date].description;
}];
[alert.view addSubview:self.timeLabel];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[timer invalidate];
}]];
[self presentViewController:alert animated:YES completion:nil];
}
時間は移動し続ける必要があり、それを何ですか?または単に静的な時間ですか? – prabodhprakash
可能な複製:http://stackoverflow.com/questions/10236167/updating-uialertview-message-dynamically-and-newline-character-issue – prabodhprakash