Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yael876

macrumors newbie
Original poster
Jan 8, 2008
6
0
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

Moderator emeritus
Jun 15, 2000
7,958
7
Something like this should work...
Code:
[[NSApp mainWindow] setContentView:myView];
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
I do this a lot in D&D Manager and I believe that the Apple suggested method is by creating an NSTabView with a single tab and using:


Code:
[[myTabView selectedTabViewItem] setView:theView];
 

MacDonaldsd

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
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

macrumors G4
Nov 3, 2005
10,434
12,250
UK
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

Code:
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem

to resize the window depending on the size required.
 

MacDonaldsd

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
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

Code:
- (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.
 

MacDonaldsd

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
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 ?
 

yael876

macrumors newbie
Original poster
Jan 8, 2008
6
0
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?
 

yael876

macrumors newbie
Original poster
Jan 8, 2008
6
0
i revealed that mainWindow return NULL

why?

how can i get the mainWindow?
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Are you using a document based application? If so you'll need to use different code as it'll be document dependent.
 

yael876

macrumors newbie
Original poster
Jan 8, 2008
6
0
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
 

MacDonaldsd

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.