0
votes

I have created a basic application, created a subclassed NSView, and added it as a custom view in interface builder. All works ok.

However certain things do not work correctly, which makes me wonder if my NSView is subclassed correctly? Specifically, when using an NSProgressIndicator, I can use startAnimating: and stopAnimating on an indeterminate, but if I try and do anything with a determinate with incrementBy it does nothing.

Even if I set the default value of the determinate NSProgressIndicator to 50.0, it appears when the app is launched at 0.0, despite looking good in IB.

My NSProgressIndicator is hooked up correctly as an IBOutlet, I can tell it to hide etc, just can't get it to animate at all. However, I also have other issues that make me think that this problem is actually my NSView subclass (such as Quick Look not firing).

In my subclass I've simply overridden the initWithFrame: and drawRect methods, calling their [super]. As I said, I've then placed this as a custom view in interface builder and changed it to MyCustomView. All works fine mostly...?

Am I subclassing this incorrectly, or not doing something in interface builder correctly? I seem to be missing some small thing?!

2

2 Answers

1
votes

Solved it.

I was initially doing the following in my awakeFromNib method:

- (void)awakeFromNib{
    [super awakeFromNib];
}

Turns out, awakeFromNib should not call super if it's directly under an NSView. Removing super fixed the issue.

- (void)awakeFromNib{
}
0
votes

You need to override initWithFrame:, not init. That is probably the issue.

Another thing to be careful of with progress indicators: if you are doing a lot of work, you might want to delay it to the next run loop iteration to let the progress indicator refresh. Use delayed performs (performSelector:withObject:afterDelay:) or something similar to allow the UI to update.