views:

53

answers:

1

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 Initial 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

A: 

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; }

Jonny
Or just call -[NSTabViewItem setView:] with your new view
Mike Abdullah
yeah, I was thinking overriding the -view method will give me chance to lazy-load tab view, but it looks NSTabView always loads all views at startup time.
Jonny