-3
私は自分の問題を解決する方法を探していましたが、見つかったのはすべて "Timer"です。 テキストフィールドでカウントダウンの値をカウントダウンとして表示する必要があります。 どうすればいいですか?iOS Objective-Cでカウントダウン
私は自分の問題を解決する方法を探していましたが、見つかったのはすべて "Timer"です。 テキストフィールドでカウントダウンの値をカウントダウンとして表示する必要があります。 どうすればいいですか?iOS Objective-Cでカウントダウン
あなたの質問は少し不明です。カウントダウンしたいですが、昇順にしますか? 時間が過ぎたり減ったりするにつれて値を大きくすることを意味しましたか?
お客様のご要望に合ったコードを作成しました。
@interface ViewController()
@property (strong, nonatomic) IBOutlet UITextField *textField;
@property int price;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_price = 1000;
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updatePrice) userInfo:nil repeats:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)updatePrice
{
_price = _price-10; // Here I'm reducing the price by 10, add to increase the price
dispatch_async(dispatch_get_main_queue(), ^{
[_textField setText:[NSString stringWithFormat:@"%ld",_price]];
});
}