我正在尝试从用户输入的数字开始倒计时,但我不确定如何实现这一点。我已对代码进行了多次尝试和更改,但它没有任何区别。
我的代码:
-(IBAction)Start
{
mainInt = minutes;
Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDown)
userInfo:nil repeats:YES];
}
我已将'minutes'声明为UITextField,以便show表示用户输入的数字是?还是不?
我在.m文件中也有@synthesised *分钟
我可以采取哪些建议让倒计时从输入UITextField的号码开始?
答案 0 :(得分:0)
这个答案应该运作良好
-(IBAction)Start
{
mainInt = [minutes.text integerValue];
Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDown)
userInfo:nil repeats:YES];
}
-(void)countDown
{
mainInt -=1;
if (mainInt ==0)
{
[Timer invalidate];
}
countDownLabel.text = [NSString stringWithFormat:@"%d",mainInt];
}
使用的变量:
minute
是用户输入数字的UITextField对象。 mainInt
属于NSInteger类型,保存更新的计数器值。 countDownLabel
是UILabel的对象,您将用它来显示更新的计数器。