View Full Version : switching NSViews
yael876
Jan 8, 2008, 08:00 AM
hello all,
i want to change problematically custom view in a window to load different NSView subclass.
i want to do it from a application subclass.
how can i get the windows instance of the current window and load it a NSView.
is it possible?
thanx
kainjow
Jan 8, 2008, 10:32 AM
Something like this should work... [[NSApp mainWindow] setContentView:myView];
Eraserhead
Jan 8, 2008, 11:44 AM
I do this a lot in D&D Manager (http://www.erasersoft.com) and I believe that the Apple suggested method is by creating an NSTabView with a single tab and using:
[[myTabView selectedTabViewItem] setView:theView];
MacDonaldsd
Jan 8, 2008, 03:53 PM
Sorry for hijacking the thread but would the same idea be used to create a preference pane like apples ?
As they have different size views for different parts of the preference pain.
Eraserhead
Jan 8, 2008, 03:56 PM
Yeah, personally I do that in D&D Manager (linked above) then I set the delegate of the tab view to my AppController file and use
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem
to resize the window depending on the size required.
MacDonaldsd
Jan 8, 2008, 04:08 PM
Yeah, personally I do that in D&D Manager (linked above) then I set the delegate of the tab view to my AppController file and use
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem
to resize the window depending on the size required.
Thanks for that Eraserhead, what you have in your application is what I am after so il follow your method.
Eraserhead
Jan 8, 2008, 04:10 PM
Thanks for that Eraserhead, what you have in your application is what I am after so il follow your method.
Btw you call NSWindow's method setFrame:display:animate: to smoothly resize the window.
MacDonaldsd
Jan 8, 2008, 04:14 PM
OK thanks again, il probably come back to this thread when I am going to do it in the next couple of weeks. Im sure il have more questions then. :D
Where do usually get your information from Eraserhead ?
Just from reading the documentation ?
Eraserhead
Jan 8, 2008, 04:31 PM
Just from reading the documentation ?
Usually that or Google, or here, either with my own thread or a site:macrumors.com Google.
yael876
Jan 9, 2008, 12:24 AM
hello
thanks for the replies.
i use what you suggest but the view doesn't change when i set the view to myView.
[win setContentView:aView];
and i don't see myView.
maybe i miss something here?
Eraserhead
Jan 9, 2008, 02:44 AM
If the setContentView doesn't work, use my TabView method.
yael876
Jan 9, 2008, 03:10 AM
i revealed that mainWindow return NULL
why?
how can i get the mainWindow?
Eraserhead
Jan 9, 2008, 03:22 AM
Are you using a document based application? If so you'll need to use different code as it'll be document dependent.
yael876
Jan 9, 2008, 03:30 AM
no i don't using a document based application....
Eraserhead
Jan 9, 2008, 06:35 AM
no i don't using a document based application....
Then do it my way as that definitely works.
kainjow
Jan 9, 2008, 10:28 AM
i revealed that mainWindow return NULL
why?
how can i get the mainWindow?
It's probably better to setup an IBOutlet for your window and use that directly, instead of relying on NSApp.
yael876
Jan 15, 2008, 05:42 AM
i tried all of your suggests but it doesn't work for me.
i have a outlet to the window and i tried to change the view from my appController but it doesn't change.
can you please help me?
thanks
yael876
Jan 15, 2008, 07:28 AM
OK it works, thanks for all....:rolleyes:
MacDonaldsd
Jan 17, 2008, 07:58 AM
Thanks for everyone's help, I got mine to work also.
One last (should be obvious) thing. How do you get the button to remain highlighted once you have pressed it in the toolbar?
kainjow
Jan 17, 2008, 08:56 AM
One last (should be obvious) thing. How do you get the button to remain highlighted once you have pressed it in the toolbar?
If you mean toolbar buttons that are selectable, you need to implement the toolbarSelectableItemIdentifiers: delegate method. See Selectable Toolbar Items (http://developer.apple.com/documentation/Cocoa/Conceptual/Toolbars/Tasks/SelectableItems.html).
MacDonaldsd
Jan 17, 2008, 03:08 PM
If you mean toolbar buttons that are selectable, you need to implement the toolbarSelectableItemIdentifiers: delegate method. See Selectable Toolbar Items (http://developer.apple.com/documentation/Cocoa/Conceptual/Toolbars/Tasks/SelectableItems.html).
What ever I have in the NSArray it does not work, the delegate method gets called though.
I have tried using NSToolbarItem, and the name that is displayed in the toolbar but none work ?
kainjow
Jan 17, 2008, 03:09 PM
The array should contain the identifiers of the items in the toolbar.
MacDonaldsd
Jan 17, 2008, 03:15 PM
Thanks again kainjow your a life saver.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.