XML 数据中的 NSStatusBar 标题行为不稳定
我想使用 XMLparser 中的字符串来“setTitle” NSStatusBar。当应用程序启动时,它会在状态栏中正确显示标题。但是,当刷新 XML 数据时,标题会显示更新后的字符串,但标题会移至状态栏中的左侧。我希望标题在 XML 刷新后保留在同一位置。
是什么原因造成的?
应用程序启动时:
刷新 XML 数据后:
这是我调用 NSStatusBar 的位置:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqual:@"temp_f"]) {
[xmlTempF appendString:@"°F"];
[degreesF setStringValue:xmlTempF];
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:xmlTempF];
[statusItem setHighlightMode:YES];
}
}
I am wanting to "setTitle" of the NSStatusBar with a string from my XMLparser. When the application starts, it shows the title in the status bar correctly. However, when the XML data is refreshed, the title displays the updated string but the title moves to the left in the status bar. I want the title to stay in the same location after the XML refreshes.
What is causing this?
upon start of the application:
after XML data is refreshed:
and here is where I'm calling the NSStatusBar:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqual:@"temp_f"]) {
[xmlTempF appendString:@"°F"];
[degreesF setStringValue:xmlTempF];
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:xmlTempF];
[statusItem setHighlightMode:YES];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这是因为您正在从
statusItemWithLength
创建一个新项目 - 您不需要重新声明statusItem
。尝试删除该行并仅更改标题。Looks like it's because you're creating a new item from
statusItemWithLength
- you shouldn't need to re-declarestatusItem
. Try removing that line and just changing the title.