设置位于变量标题之前的静态窗口标题
对于令人困惑的帖子标题,我深表歉意。这就是我的意思:
假设我有一个显示窗口标题文本的操作。这是一个非基于文档的应用程序。
[window setTitle:@"Completed"];
我想向这个返回的字符串添加一个静态标题。类似于“状态”之类的东西。因此,当触发操作时,窗口标题将显示:
Status:Completed 或 Status:Incomplete 等。
因此,“Status”始终位于变量字符串之前。变量字符串反映基于应用程序中另一个操作而存在的字符串。因此,我无法通过简单地执行以下操作来实现我正在寻找的结果:
[window setTitle:@"Status:Completed"]; etc, etc.
我怎样才能做到这一点?
谢谢
保罗
I apologize for the confusing post Title. This is what I mean:
Lets say I have an action that displays window title text. It's a non doc based app.
[window setTitle:@"Completed"];
I want to add a static title to this returned string. Something like "Status." So when the action is triggered, the window title reads:
Status:Completed, or Status:Incomplete, etc.
So "Status" always preceeds the variable string. The variable string reflects a string that exists based on another action in the app. So I cannot achieve the results that I am looking for by simply doing:
[window setTitle:@"Status:Completed"]; etc, etc.
How can I do this?
thanks
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要么子类化 NSWindow,要么向 NSWindow 添加一个类别,例如使用所需前缀调用
-setTitle:
的-setStatus:
。如果这些都不起作用,您可以观看
NSWindowDidUpdateNotification
并更新标题(如果它缺少您的前缀)。该通知被记录为在绘制窗口之前发送,因此您不应该有任何闪烁。或者,您可以使用绑定来观看-title
并执行相同的操作。绑定可能会有更好的性能,因为您只会在标题实际更改时调用代码。Either subclass NSWindow or add a category to NSWindow like
-setStatus:
that calls-setTitle:
with your desired prefix.If none of this is workable, you can watch
NSWindowDidUpdateNotification
and update the title if it lacks your prefix. This notification is documented to be sent before the window is drawn, so you shouldn't have any flickering. Alternately you could use bindings to watch-title
and do the same thing. Bindings would possibly have a little better performance, since you'd only call your code when the title actually changes.