NSView only redraws on breakpoint
Posted
by
Jacopo
on Stack Overflow
See other posts from Stack Overflow
or by Jacopo
Published on 2012-09-08T23:15:55Z
Indexed on
2012/09/09
3:38 UTC
Read the original article
Hit count: 142
objective-c
|cocoa
I have a custom view inside a NSPopover
. It should change according to user input and it does the first time the user interact with it but it fails to redraw the following times.
I have tried to put an NSLog
inside the -drawRect:
method and it doesn't get called during normal execution. When I try to debug and put a breakpoint inside the method it gets called normally and the app works as it should.
I explicitly call the view -setNeedsDisplay:
method every time I need it to redraw.
I don't understand why it should make a difference.
Here is the code that update the status of the view. These methods are part of the NSTextField
delegate method -textDidChange:
and I checked that these get called every time the user type something in the textfield associated with popover.
[tokenCloud tokensToHighlight:[NSArray arrayWithObject:completeSuggestionString]];
tokenCloud.tokens = filteredTokens;
[tokenCloud setNeedsDisplay:YES];
The views is a series of recessed button. The first line update the status of all the buttons in the popover and the second add or delete buttons. They both work properly because the first time they are called the view is update properly. I have also checked that both the status of the buttons in tokenCloud
and its property tokens
are updated correctly. The problem is that the NSView
subclass, tokenCloud
, doesn't redraw so the changes are not reflected in the UI the second time.
Here is the draw method of the view:
- (void)drawRect:(NSRect)rect {
[self recalculateButtonLocations];
NSLog(@"Redrawn");
}
Again this method gets called normally every time I update the view if I place a breakpoint in [self recalculateButtonLocations];
. If instead I let the app run normally nothing gets logged in the console the second time I update the view. Same thing if I include the NSLog
in the recalculateButtonLocations
method, nothing gets logged the second time meaning that the method is not called.
© Stack Overflow or respective owner