gpt4 book ai didi

ios - 意外的应用程序崩溃

转载 作者:行者123 更新时间:2023-11-28 22:22:10 25 4
gpt4 key购买 nike

当我通过 xcode 构建我的应用程序时,当我按下链接到 starttimer: 的按钮时它总是崩溃。它突出显示了代码中的最后一个大括号。重要的是要注意,当我通过模拟器启动应用程序时,我可以单击按钮而不会崩溃。发生了什么?这是一些代码:

@implementation TimeController

int timeTick = 0;


NSTimer *timer;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
labelTime.text = @"0";
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)startTimer:(id)sender {
[timer invalidate];
timer= [NSTimer scheduledTimerWithTimeInterval:1.0 target:(self) selector:(@selector(tick)) userInfo:(nil) repeats:(YES)];
}

- (IBAction)resetTicktock:(id)sender {
[timer invalidate];
timeTick=0;
labelTime.text = @"0";
}

-(void)tick{
timeTick++;
NSString *timeString = [[NSString alloc] initWithFormat:@"%d", timeTick];
labelTime.text = timeString;
}




@end

提前致谢!

最佳答案

调用方法时不需要 ()。

代替

timer= [NSTimer scheduledTimerWithTimeInterval:1.0 target:(self) selector:(@selector(tick)) userInfo:(nil) repeats:(YES)];

你应该有

timer= [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tick) userInfo:nil repeats:YES];

关于ios - 意外的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20039460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com