显示主机菜单时更新NSMenuItem

| 我需要更新“ 0”以显示进度(例如Time Machine对其进行备份)。问题是当我在那个
NSMenuItem
上设置一个新的
title
时,the1并没有改变。 实际上,当我关闭并重新打开菜单时,它正在更改,但是我想在用户查看菜单时对其进行更新。 我也尝试删除一个项目并重新插入它,但没有结果。 有指针吗?     
已邀请:
        如果您的更新代码在菜单跟踪期间使用的运行循环模式下运行,则实际上无需花费额外的精力。这是
NSEventTrackingRunLoopMode
,但是您可能只想使用
NSRunLoopCommonModes
,所以当下拉菜单时菜单项标题是正确的。 这是菜单项
foo
的简单示例,该菜单项计算自应用启动以来的秒数:
- (void)doStuff;
{
    static int i = 0;
    [foo setTitle:[NSString stringWithFormat:@\"%d\", ++i]];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
{
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
                                [self methodSignatureForSelector:@selector(doStuff)]];
    [invocation setTarget:self];
    [invocation setSelector:@selector(doStuff)];
    [[NSRunLoop mainRunLoop] addTimer:[NSTimer timerWithTimeInterval:1 invocation:invocation repeats:YES] forMode:NSRunLoopCommonModes];
}
    

要回复问题请先登录注册