Cocoa - 在另一个xib上显示xib [英] Cocoa - Display xib on another xib

查看:238
本文介绍了Cocoa - 在另一个xib上显示xib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何(或指示我信息)在另一个.xib(nib)上显示.xib(nib)。

Can anyone tell me how (or direct me to info on) displaying a .xib (nib) on another .xib (nib).

(这显然不起作用)

- (void)drawRect:(NSRect)dirtyRect
{

    NSRect customView = NSMakeRect(pos1, pos1, 200, 100);

    [[NSBundle mainBundle] loadNibNamed:@"secondXib" owner:self];

    NSRectFill (customView);
}

我想为Mac OS X (顺便使用xCode 4 incase它有所不同)

And I wish to do this for Mac OS X (Not iPhone). (By the way using xCode 4 incase it makes a difference)

推荐答案

您可以很容易地从另一个nib加载视图使用 NSViewController 。在您的nib中,您只需将文件所有者的自定义类设置为 NSViewController ,并连接视图 文件所有者的插口指向要加载的视图。您可以这样做:

You can easily load a view from another nib using NSViewController. In your nib you should just set File's Owner's custom class to NSViewController and hook up the view outlet of File's Owner to point to the view you want to load. You can then just do this:

//create an NSViewController and use it to load the nib
NSViewController* vc = [[NSViewController alloc] initWithNibName:@"YourNibName" bundle:nil];
//get the view from the view controller
NSView* loadedView = [vc view];
//release the view controller so we don't leak
[vc release];
//add the view as a subview of your main view
[mainView addSubview:loadedView];
//position the view
[loadedView setFrameOrigin:NSMakePoint(100.0, 100.0)];

您不需要在中执行任何操作drawRect:。子视图将绘制自己,如果你移动子视图, drawRect:将被自动调用。

You don't need to do anything in drawRect:. The subview will draw itself, and drawRect: will be called automatically if you move the subview.

查看可可编程指南。这是很重要的理解视图如何工作,从你的问题很清楚,你还没有这样的理解。

You should read the View Programming Guide for Cocoa. It is critical to understanding how views work, and it is clear from your question that you do not yet have that understanding.

您还应该阅读 Cocoa绘图指南

这篇关于Cocoa - 在另一个xib上显示xib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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