开发者

deriving from NSTabViewItem

I'm writing a Cocoa app. One dialog has 3 tabs, some of the tabs needs more loading time, so I want to load them lazily. Since each Tab is a NSTabViewItem class, so I'm trying to derive from it and overriding its view property. In the view getter method, I use a ViewController to load a view and returns out. In Debugging, I found NSTabViewItem -view method is get called correctly, but after that NSTabView tries to set Ini开发者_开发知识库tial FirstResponder and crashed with message:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'In -[NSTabViewItem setInitialFirstResponder:], the first responder must descend from the tab view item's view. (Item: Invalid responder: )'

I tried to override the -initialFirstResponder method to return a sub-view of my loaded view, but it still crashes the same place.

does anyone know how to get it work correctly? Also is it correct way to do this by deriving the NSTabViewItem?

thanks! -Jonny


OK, I understand the exception now. The NSTabViewItem has its view, so I should use its view and add my new view as a subview, like:

-(NSView*)view {
   NSView* view = [super view];
   NSVIew* myView = //load view from nib
   [view addSubView:myView];
   return view;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜