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

themacster298

macrumors member
Original poster
Feb 20, 2011
55
0
Hello, I am using Matt Gemells status item code and I am having rouble switching between two views.

I have created an array that holds both NSViews that I want to switch to and a integer with the value of 0 in it.

What I was trying to do was to create a button that, when pressed, changed the value of the integer to 1.

It worked, but you must open and close the window for it to work properly.

How would I make it work so that it switches instantly?


Code:
Code:
- (void)toggleAttachedWindowAtPoint:(NSPoint)pt
{
    // Attach/detach window.
    if (!attachedWindow) {
        [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
        attachedWindow = [[MAAttachedWindow alloc] initWithView:[arrayviews objectAtIndex:viewhold]
                                                attachedToPoint:pt 
                                                       inWindow:nil 
                                                         onSide:MAPositionAutomatic
                                                     atDistance:5.0];
        [attachedWindow makeKeyAndOrderFront:self];
        
    } else {
        [attachedWindow setAlphaValue:1.0];
        [[attachedWindow animator] setAlphaValue:0.0];
        //[attachedWindow orderOut:self];
        [attachedWindow release];
        attachedWindow = nil;
    }    
}


-(IBAction)openprefs:(id)sender {
    viewhold = 1;

}
 
Put an NSTabView in your MAAttachedWindow. Add your subviews to the NSTabView as NSTabViewItems.

Set the tab-type of the NSTabView to one of the NSNoTabsXXX tab-types (see NSTabViewType enum), so the tabs aren't drawn. Then switch between subviews by passing the integer to selectTabViewItemAtIndex: .

This is a fairly common way to get multiple independent subviews, where only one can appear at a time.
 
Put an NSTabView in your MAAttachedWindow. Add your subviews to the NSTabView as NSTabViewItems.

Set the tab-type of the NSTabView to one of the NSNoTabsXXX tab-types (see NSTabViewType enum), so the tabs aren't drawn. Then switch between subviews by passing the integer to selectTabViewItemAtIndex: .

This is a fairly common way to get multiple independent subviews, where only one can appear at a time.

I cannot thank you enough.

But, just one more question.

What if I wanted to have a view with a different size?
 
What if I wanted to have a view with a different size?

Describe what you want to happen.

Is the window always the size of the largest view? Does the window change size to accomodate the larger view, and shrink to accomodate smaller views? In which directions does the size change, vertically or horizontally or both?
 
Describe what you want to happen.

Is the window always the size of the largest view? Does the window change size to accomodate the larger view, and shrink to accomodate smaller views? In which directions does the size change, vertically or horizontally or both?

Well, the program's main window is a custom view that you can resize to your desire.

What I am asking is, how can I switch between 2 different custom views (with different sizes) within the same .nib file?
 
Well, the program's main window is a custom view that you can resize to your desire.

Then if you need it to be a certain size, you will have to constrain it to be that certain size.

What I am asking is, how can I switch between 2 different custom views (with different sizes) within the same .nib file?
I asked you describe what you want to happen. From the user's perspective, what happens on-screen when the two different-sized views appear and disappear. You haven't done that yet.

I already described how to switch between two different views using an NSTabView. If both custom views are within the same .nib file, then add an NSTabView, configure its options, and put your custom subviews into it as tab-items.

Have you tried any of this yet? Have you looked up any Apple sample code that uses NSTabView? Or are you waiting for a complete step-by-step answer that accounts for every possible detail?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.