PDA

View Full Version : Switch views




themacster298
Jul 22, 2012, 01:26 PM
Hello, I am using Matt Gemells status item code (http://mattgemmell.com/2008/03/04/using-maattachedwindow-with-an-nsstatusitem/) 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:
- (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;

}



chown33
Jul 22, 2012, 01:59 PM
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.

themacster298
Jul 22, 2012, 03:32 PM
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?

chown33
Jul 22, 2012, 04:54 PM
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?

themacster298
Jul 22, 2012, 08:01 PM
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?

chown33
Jul 23, 2012, 12:06 PM
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?