开发者

"Menubar-Widget" doesn't update its interface

开发者 https://www.devze.com 2023-03-25 06:33 出处:网络
I\'m trying to create a small \"Menubar-Widget\". So it\'s not really a widget, but it\'s a Cocoa-Appl开发者_如何学运维ication, which has no icon in the dock but an icon in the menu- or statusbar.

I'm trying to create a small "Menubar-Widget". So it's not really a widget, but it's a Cocoa-Appl开发者_如何学运维ication, which has no icon in the dock but an icon in the menu- or statusbar.

You can fire a NSTimer by clicking a button, and then it should show a countdown. But it doesn't...

- (void)update {
    NSTimeInterval interval = [endDate timeIntervalSinceNow];

    int _seconds = (int)interval%60;
    int _minutes = (((int)interval-_seconds)/60)%60;
    int _hours = ((int)interval-_seconds-_minutes*60)%3600;

    timeLeft.stringValue = [NSString stringWithFormat:@"%i:%i:%i",_hours,_minutes,_seconds];

    NSLog(@"%i:%i:%i",_hours,_minutes,_seconds);
}

So what happen exactly?

When I fire the timer, the interface won't update the timeLeft Label. NSLog() won't work too. But if I close the box, the NSLog says me the correct time and if I open the box again, it's showing me the right thing. But it won't update anymore 'til I close the box again.

"Menubar-Widget" doesn't update its interface


I replaced the relative time with an absolute time (e.g. 2:45 pm)... Interface is still not updating, but it's ok.

0

精彩评论

暂无评论...
验证码 换一张
取 消