我创建了一个计数计时器(在标签上)和一个包含标签整数值的变量(命名为计数)。我还创建了一个函数来检查我的数字是 7,除以 7 还是包含 7。当我尝试将我的计数值传递给检查函数时,我的应用程序是堆栈。我尝试了很长时间来找出堆栈溢出发生的原因,但我没有成功。我该如何解决?这是我的代码:
-(IBAction)start:(id)sender
{
timer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
MainInt = 0;
numbersTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(countup) userInfo:nil repeats:YES];
}
-(void)countup
{
MainInt += 1;
numbersLabel.text = [NSString stringWithFormat:@"%i", MainInt];
count = numbersLabel.text.intValue;
NSLog(@"num: %d", count);
if ([self checknum:(count) == false]) {
NSLog(@"BOOM");
}
}
-(BOOL)checknum:(int)number
{
while (number<10)
{
if(number ==7)
{
NSLog(@"boom, i=%d", number);
return true;
}
}
while (number>=10 && number<1000)
{
if(number % 7 == 0)
{
NSLog(@"boom i=%d", number);
return true;
}
if([self revese:(number)])
{
NSLog(@"boom reverse num = %d", number);
return true;
}
}
return false;
}
-(BOOL) revese:(int)number
{
if(number < 10 && number != 7)
return false;
if(((number % 10) == 7) || ((number / 10) == 7))
return true;
else {
[self revese:(number / 10)];
}
return false;
}
谢谢!