实际上,当我关闭并重新打开菜单时,它正在改变,但是我想在用户查看时更新它.
我也尝试删除一个项目,并重新插入它没有结果.
任何指针?
解决方法 如果更新代码在菜单跟踪期间使用的 run loop mode中运行,则实际上无需额外的工作.这是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];}总结
以上是内存溢出为你收集整理的可可 – 在显示主菜单时更新NSMenuItem全部内容,希望文章能够帮你解决可可 – 在显示主菜单时更新NSMenuItem所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)