use*_*691 4 macos cocoa objective-c xib nib
任何人都可以告诉我如何(或指示我的信息)在另一个.xib(笔尖)上显示.xib(笔尖).
我怎么想放置它所以我可以以编程方式将它移动到主要的笔尖类似这样(显然不起作用)
- (void)drawRect:(NSRect)dirtyRect
{
NSRect customView = NSMakeRect(pos1, pos1, 200, 100);
[[NSBundle mainBundle] loadNibNamed:@"secondXib" owner:self];
NSRectFill (customView);
}
Run Code Online (Sandbox Code Playgroud)
我希望为Mac OS X(非iPhone)做到这一点.(顺便说一句,使用xCode 4会有所不同)
您可以使用从另一个笔尖轻松加载视图NSViewController.在你的笔尖中,你应该只设置文件所有者的自定义类,NSViewController并连接文件所有者的view出口以指向要加载的视图.然后你可以这样做:
//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)];
Run Code Online (Sandbox Code Playgroud)
你不需要做任何事情drawRect:.子视图将自行绘制,drawRect:如果移动子视图,将自动调用.
您应该阅读Cocoa的View Programming Guide.理解视图的工作方式至关重要,从您的问题中可以清楚地看出,您还没有这种理解.
您还应阅读" 可可绘图指南".