PanicDev
PanicDev

Reputation: 325

Unexpected app crashing

When I build my app through xcode, it always crashes when I press the button linked to starttimer:. It highlights the last curly bracket in the code. It is important to note that when I launch the app through the simulator, I am able to click the button without a crash. What's happening? Here's some code:

@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

Thanks in advance!

Upvotes: 0

Views: 91

Answers (1)

Cutetare
Cutetare

Reputation: 909

You don't need () when calling a method.

Instead of

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

You should have

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

Upvotes: 2

Related Questions