Cocoa:将子视图添加到来自不同类和笔尖的视图
如果我有两个带有多个视图的笔尖,有没有办法在它们之间使用 addSubview: 方法?我想做的是从其中一个笔尖获取视图,并告诉它添加一个子视图,该子视图将是另一个笔尖文件中的视图。
我将它们放在单独的笔尖中的原因是因为第二个笔尖的子视图将使用相同的模板但不同的参数添加多次。
If i have two nibs with several views, is there a way for me to use the addSubview: method between them? What I would like to do is take a view from one of the nibs and tell it to add a subview that would be a view in the other nib file.
The reason I have them in separate nibs is because the subview from the second nib will be added several times, using the same template but different parameters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以将一个笔尖中的视图作为子视图添加到另一笔尖中的视图。
您需要创建一个拥有子笔尖的 NSViewController 对象。因此,一旦初始化视图控制器,与其关联的笔尖就会被加载。现在您可以使用控制器的 view 属性并将其作为子视图添加到任何其他视图。
下面的代码将帮助您更好地理解:
YourViewController.m
YourOtherClass.m
Yes, you can add a view in one nib as a subview to the view in another nib.
You need to create a NSViewController object which will own the child nib. So that as soon as you initialize the view controller the nib associated with it is loaded. Now you can use the view property of the controller and add it as a subview to any other view.
The code below will help you understand better:
YourViewController.m
YourOtherClass.m