switching NSViews

Discussion in 'Mac Programming' started by yael876, Jan 8, 2008.

  1. yael876 macrumors newbie

    Joined:
    Jan 8, 2008
    #1
    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
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Something like this should work...
    Code:
    [[NSApp mainWindow] setContentView:myView];
     
  3. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #3
    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];
    
     
  4. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #4
    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.
     
  5. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #5
    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.
     
  6. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #6
    Thanks for that Eraserhead, what you have in your application is what I am after so il follow your method.
     
  7. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #7
    Btw you call NSWindow's method setFrame:display:animate: to smoothly resize the window.
     
  8. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #8
    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 ?
     
  9. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #9
    Usually that or Google, or here, either with my own thread or a site:macrumors.com Google.
     
  10. yael876 thread starter macrumors newbie

    Joined:
    Jan 8, 2008
    #10
    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?
     
  11. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #11
    If the setContentView doesn't work, use my TabView method.
     
  12. yael876 thread starter macrumors newbie

    Joined:
    Jan 8, 2008
    #12
    i revealed that mainWindow return NULL

    why?

    how can i get the mainWindow?
     
  13. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #13
    Are you using a document based application? If so you'll need to use different code as it'll be document dependent.
     
  14. yael876 thread starter macrumors newbie

    Joined:
    Jan 8, 2008
    #14
    no i don't using a document based application....
     
  15. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #15
    Then do it my way as that definitely works.
     
  16. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #16
    It's probably better to setup an IBOutlet for your window and use that directly, instead of relying on NSApp.
     
  17. yael876 thread starter macrumors newbie

    Joined:
    Jan 8, 2008
    #17
    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
     
  18. yael876 thread starter macrumors newbie

    Joined:
    Jan 8, 2008
  19. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #19
    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?
     
  20. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #20
    If you mean toolbar buttons that are selectable, you need to implement the toolbarSelectableItemIdentifiers: delegate method. See Selectable Toolbar Items.
     
  21. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #21
    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 ?
     
  22. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #22
    The array should contain the identifiers of the items in the toolbar.
     
  23. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK

Share This Page