开发者

How to tell what's causing drawRect to be called?

I've got my cus开发者_运维知识库tom NSView with a bunch of custom buttons in it, the buttons are added as a subView in the NSView's drawRect method.

Now I'm finding that after pressing a button the drawRect of the parent view is repeatedly called. Sometimes it only stops when I quit the app - I know this from a simple log statement in drawRect.

Now I know there are probably bigger architectural issues in my app causing this, where do I go to begin tracking down what's causing this view to be repeatedly redrawn?

Thanks!


First of all you shouldn't be adding subviews in drawRect:.

Are you doing any custom drawing or are you just adding subviews? If you're not doing any drawing, you should not implement drawRect:.

You want to add the subviews in initWithFrame: and then you want to set the frames of the subviews in layoutSubviews based on self.bounds.

If you have any questions, feel free to ask.

EDIT: Just realized that you were asking about NSView and not UIView. I've never used NSView, but perhaps they work similarly.

EDIT 2: I read a bit about NSView and it doesn't seem to have layoutSubviews. Perhaps you should set the frames in drawRect:? I'm still pretty sure you don't want to add subviews in drawRect:.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜