Interface Builder NSScrollView无法与IB定义的视图一起使用 [英] Interface Builder NSScrollView not working with IB defined View

查看:64
本文介绍了Interface Builder NSScrollView无法与IB定义的视图一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个名为Drawing的drawRect定义了一个自定义类。我已经在NIB中布置了视图,以包含一个带有Drawing子视图的NSScrollView。当我启动程序时,屏幕为空白。有趣的是,当我以编程方式为NSScrollView创建documentView时,在滚动视图中得到了一个图像。当我在setDocumentView中为笔尖使用实例时,什么也没得到。

I have defined a custom class with a drawRect called Drawing. I have laid out the view in my NIB to contain an NSScrollView with a Drawing subview. When I launch the program, the screen is blank. Interestingly, when I create the documentView for the NSScrollView programmatically, I get an image in my scroll view. When I use the instance for the nib in my setDocumentView, I get nothing.

因此,如果在IB中设置了Drawing视图,

So if the Drawing view is set in IB,

[_scrollViewWorkspace setDocumentView:_drawing]; //does not work.

但是

[_scrollViewWorkspace setDocumentView:[[Drawing alloc] initWithFrame:NSMakeRect(0,0,[[_scrollViewWorkspace documentView ]bounds].size.width, [[_scrollViewWorkspace documentView] bounds ].size.height)]];

效果很好!

为什么可以?

推荐答案

解决了!

当我在Interface Builder中放置视图时,我只是将自定义视图拖到画布中的NSScrollView上。我重新布局,以便使用Embed-> Scroll View并成功。

When I laid the view out in Interface Builder I just dragged the custom view to the NSScrollView in the canvas. I re-did the layout so that I used Embed->Scroll View and it worked.

Bruce

这篇关于Interface Builder NSScrollView无法与IB定义的视图一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆