• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSViewController and View Swapping
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSViewController and View Swapping


  • Subject: Re: NSViewController and View Swapping
  • From: Jonathan Dann <email@hidden>
  • Date: Mon, 14 Jul 2008 20:55:49 +0100

NSView has a method -replaceSubview:with:

see:
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#/ /apple_ref/occ/instm/NSView/replaceSubview:with:


So you need to have some setup where you can keep track of you view controllers, even in a non-document based app, if the app is non- trivial you'll end up subclassing NSWindowController, so keep an array or any collection of view controllers in the window controller.

Then make some method (be it an IBAction, or whatever) that is invoked by your button which gets the new view from its view controller and passes that (and the current view) to -replaceSubview:with:

If the view you want to replace it the content view of the window you can just call something like [window setContentView:[myViewController view]];

Still, I'd have a look at NSTabView, you can still use view controllers for each of the views in the tab view.

HTH

Jon


On 14 Jul 2008, at 15:26, Brad Gibbs wrote:

OK, thanks for the tip. I think this will work well for the situation I described.

But, that screen (with its tab view and all of the custom views to be made available from within the tab view) is one of several screens like it. The other tab views will contain different numbers of tabs. The user will be able to choose among the screens from a pop-up menu on a status bar at the top of the screen. So, I still need a way to swap out one set of tab views with another, without using a box, in a non-document-based application. So, I think I still need to solve the problem of how to change:

[box setContentView:v]

to swap out one custom tab view with another, so that when the user selects another set of tab views, the current tab view is swapped out and replaced by the newly-selected tab view.


Thanks again.

Brad




On Jul 14, 2008, at 12:17 AM, Scott Anguish wrote:

you can still do it with NSTabView

use setTabViewType to one of the following
NSNoTabsBezelBorder = 4, NSNoTabsLineBorder = 5, NSNoTabsNoBorder = 6


have your button actions change the visible tab using one of...

- (void)selectTabViewItemAtIndex:(NSInteger)index

- (void)selectTabViewItemWithIdentifier:(id)identifier


- (void)selectTabViewItem:(NSTabViewItem *)tabViewItem





On 14-Jul-08, at 2:04 AM, Brad Gibbs wrote:

Thanks for the quick response and the links.

NSTabView with tabs on the bottom is exactly what I'm looking for, except, I'm writing a fullscreen app with stylized NSImage buttons, rather than tabs. I'm still looking through the ViewController sample code. Given the number of single window apps out there today, it seems like swapping views should be one of those common things that is easy to accomplish with Cocoa, rather than an uncommon thing that's merely possible...



On Jul 13, 2008, at 10:46 PM, Nathan Kinsinger wrote:


On Jul 13, 2008, at 11:15 PM, Brad Gibbs wrote:

I'm trying to create a Cocoa app with a single window with a number of views that get swapped in and out, using an NSViewController for each of the views.

I have a series of buttons along the bottom of the UI in a custom view, and another custom view above the row of buttons. When button A is pressed, view A should appear in the custom view above the row of buttons, and button A should be turned on. When button B is pressed, view A should be replaced by View B, button A should turn off and button B should turn on. Ultimately, I'd like to do this with an animation (view A fades out and view B fades in). For now, I'd be happy just replacing A with B.

I haven't been able to find much in the documentation about NSViewController for Cocoa. I have the Hillegass book, but the view swapping example in Chapter 29 is done with a document- based application and the views there are contained in an NSBox:

...
NSView *v = [vc view];
[box setContentView:v];
...

I don't know Cocoa well enough to adapt this example for a non- document-based application without an NSBox. Could someone please point me to documentation for NSViewController, other than the NSViewController Reference, or provide me with a quick explanation or example code that will do this? I've read through the Katidev blog on XSViewController and XSWindowController, but, again, that's a document-based example, and it doesn't explicitly provide methods for replacing one view with another.


Thanks in advance.

Brad

There is an example at: http://developer.apple.com/samplecode/ViewController/index.html

Also what you are describing sounds a lot like an NSTabView with the style set to Bottom Tabs. Try creating one in IB and playing with it. Also look at:
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/TabView/TabView.html
and an example with animation at:
http://developer.apple.com/samplecode/Reducer/index.html


--Nathan

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
@cocoadoc.com


This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSViewController and View Swapping (From: Brad Gibbs <email@hidden>)
 >Re: NSViewController and View Swapping (From: Nathan Kinsinger <email@hidden>)
 >Re: NSViewController and View Swapping (From: Brad Gibbs <email@hidden>)
 >Re: NSViewController and View Swapping (From: Scott Anguish <email@hidden>)
 >Re: NSViewController and View Swapping (From: Brad Gibbs <email@hidden>)

  • Prev by Date: Rounded NSWindow corners?
  • Next by Date: NSTextField labels and URLs
  • Previous by thread: Re: NSViewController and View Swapping
  • Next by thread: Re: NSViewController and View Swapping
  • Index(es):
    • Date
    • Thread