Question

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:

enter image description here

after XML data is refreshed:

enter image description here

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];
    }
}
Was it helpful?

Solution

Looks like it's because you're creating a new item from statusItemWithLength - you shouldn't need to re-declare statusItem. Try removing that line and just changing the title.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top