从不同的笔尖添加 NSView
当新视图位于不同的 xib 文件中时,如何添加子视图?
不同笔尖的类是 NSViewController,我正在使用 self = [super initWithNibName:@"NewView" bundle:nil]; 来加载笔尖
我可以做类似的事情
NewView *nv = [NewView new];
[oldView removeFromSuperView];
[mv addSubview:[nv theView]];
吗?必须做一些不同的事情
How can I add a subview when the new view is in a different xib file?
The class for the different nib is an NSViewController and I'm using self = [super initWithNibName:@"NewView" bundle:nil];
to load the nib
Can I just do something like:
NewView *nv = [NewView new];
[oldView removeFromSuperView];
[mv addSubview:[nv theView]];
or do I have to do something different
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是正确的,只要
NewView
是NSViewController
的子类。话虽如此,您不应该将控制器类命名为 NewView,因为它不是视图。您的NSViewController
子类实际上应该命名为NewViewController
。您也可以这样做:
当然,这假设您的
NewView
nib 文件的文件所有者设置为您的NSViewController
子类。Yes, that's correct, providing
NewView
is a subclass ofNSViewController
. Having said that, you shouldn't name a controller classNewView
, as it's not a view. Your subclass ofNSViewController
should really be namedNewViewController
.You can also do this:
Of course, this assumes that your
NewView
nib file has its File's Owner set your subclass ofNSViewController
.