Skip to content
Browse files

Switching between views without animation.

  • Loading branch information...
1 parent b1bdfc0 commit 89ec4c803335a9aecf4cb4d982652c90f66208cd @tomaz committed
View
3 Example3/LionTableViewTesting/LionAutoLayoutTestingAppDelegate.h
@@ -8,6 +8,9 @@
@interface LionAutoLayoutTestingAppDelegate : NSObject <NSApplicationDelegate>
+- (IBAction)changeToViewController1:(id)sender;
+- (IBAction)changeToViewController2:(id)sender;
+
@property (nonatomic, unsafe_unretained) IBOutlet NSWindow *window;
@property (nonatomic, weak) IBOutlet NSView *placeholderView;
View
32 Example3/LionTableViewTesting/LionAutoLayoutTestingAppDelegate.m
@@ -12,7 +12,8 @@
#import "LionAutoLayoutTestingAppDelegate.h"
@interface LionAutoLayoutTestingAppDelegate ()
-- (void)changePlaceholderWithViewFromController:(NSViewController *)controller;
+- (void)replacePlaceholderViewWith:(NSViewController *)controller;
+@property (nonatomic, strong) NSViewController *currentViewController;
@property (nonatomic, strong) ViewController1 *viewController1;
@property (nonatomic, strong) ViewController2 *viewController2;
@end
@@ -23,17 +24,44 @@ @implementation LionAutoLayoutTestingAppDelegate
@synthesize window = _window;
@synthesize placeholderView = _placeholderView;
+@synthesize currentViewController = _currentViewController;
@synthesize viewController1 = _viewController1;
@synthesize viewController2 = _viewController2;
#pragma mark - NSApplicationDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)note {
+ [self replacePlaceholderViewWith:self.viewController1];
+}
+
+#pragma mark - User actions
+
+- (IBAction)changeToViewController1:(id)sender {
+ [self replacePlaceholderViewWith:self.viewController1];
+}
+
+- (IBAction)changeToViewController2:(id)sender {
+ [self replacePlaceholderViewWith:self.viewController2];
}
#pragma mark - Helpers
-- (void)changePlaceholderWithViewFromController:(NSViewController *)controller {
+- (void)replacePlaceholderViewWith:(NSViewController *)controller {
+ if (controller == self.currentViewController) return;
+ self.currentViewController = controller;
+ NSView *placeholderView = self.placeholderView;
+ NSView *currentView = self.placeholderView.subviews.lastObject;
+ NSView *newView = self.currentViewController.view;
+ if (currentView) {
+ [currentView removeFromSuperview];
+ }
+ if (newView) {
+ NSDictionary *views = NSDictionaryOfVariableBindings(newView);
+ [newView setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [placeholderView addSubview:newView];
+ [placeholderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[newView]|" options:0 metrics:nil views:views]];
+ [placeholderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[newView]|" options:0 metrics:nil views:views]];
+ }
}
#pragma mark - Properties
View
76 Example3/LionTableViewTesting/View1.xib
@@ -44,6 +44,7 @@
<string key="NSFrame">{{384, 12}, {82, 32}}</string>
<reference key="NSSuperview" ref="1005"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:687</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="204839193">
@@ -71,6 +72,7 @@
<string key="NSFrame">{{14, 12}, {82, 32}}</string>
<reference key="NSSuperview" ref="1005"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="501001616"/>
<string key="NSReuseIdentifierKey">_NS:687</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="907652163">
@@ -94,6 +96,7 @@
<string key="NSFrame">{{384, 224}, {82, 32}}</string>
<reference key="NSSuperview" ref="1005"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="338297739"/>
<string key="NSReuseIdentifierKey">_NS:687</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="712428225">
@@ -117,6 +120,7 @@
<string key="NSFrame">{{14, 224}, {82, 32}}</string>
<reference key="NSSuperview" ref="1005"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="728347377"/>
<string key="NSReuseIdentifierKey">_NS:687</string>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="396300838">
@@ -138,7 +142,7 @@
<string key="NSFrameSize">{480, 272}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
+ <reference key="NSNextKeyView" ref="412916573"/>
<string key="NSClassName">NSView</string>
</object>
</array>
@@ -152,6 +156,38 @@
</object>
<int key="connectionID">2</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeToViewController2:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="412916573"/>
+ </object>
+ <int key="connectionID">19</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeToViewController2:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="728347377"/>
+ </object>
+ <int key="connectionID">20</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeToViewController2:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="338297739"/>
+ </object>
+ <int key="connectionID">21</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeToViewController2:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="501001616"/>
+ </object>
+ <int key="connectionID">22</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -452,11 +488,47 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">18</int>
+ <int key="maxID">22</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
+ <string key="className">LionAutoLayoutTestingAppDelegate</string>
+ <string key="superclassName">NSObject</string>
+ <dictionary class="NSMutableDictionary" key="actions">
+ <string key="changeToViewController1:">id</string>
+ <string key="changeToViewController2:">id</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="actionInfosByName">
+ <object class="IBActionInfo" key="changeToViewController1:">
+ <string key="name">changeToViewController1:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo" key="changeToViewController2:">
+ <string key="name">changeToViewController2:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="outlets">
+ <string key="placeholderView">NSView</string>
+ <string key="window">NSWindow</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="placeholderView">
+ <string key="name">placeholderView</string>
+ <string key="candidateClassName">NSView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="window">
+ <string key="name">window</string>
+ <string key="candidateClassName">NSWindow</string>
+ </object>
+ </dictionary>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/LionAutoLayoutTestingAppDelegate.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">NSLayoutConstraint</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
View
70 Example3/LionTableViewTesting/View2.xib
@@ -151,6 +151,38 @@
</object>
<int key="connectionID">2</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeToViewController1:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="641689623"/>
+ </object>
+ <int key="connectionID">19</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeToViewController1:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="445657846"/>
+ </object>
+ <int key="connectionID">20</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeToViewController1:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="710096892"/>
+ </object>
+ <int key="connectionID">21</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeToViewController1:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="703656838"/>
+ </object>
+ <int key="connectionID">22</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -451,11 +483,47 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">18</int>
+ <int key="maxID">22</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
+ <string key="className">LionAutoLayoutTestingAppDelegate</string>
+ <string key="superclassName">NSObject</string>
+ <dictionary class="NSMutableDictionary" key="actions">
+ <string key="changeToViewController1:">id</string>
+ <string key="changeToViewController2:">id</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="actionInfosByName">
+ <object class="IBActionInfo" key="changeToViewController1:">
+ <string key="name">changeToViewController1:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo" key="changeToViewController2:">
+ <string key="name">changeToViewController2:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="outlets">
+ <string key="placeholderView">NSView</string>
+ <string key="window">NSWindow</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="placeholderView">
+ <string key="name">placeholderView</string>
+ <string key="candidateClassName">NSView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="window">
+ <string key="name">window</string>
+ <string key="candidateClassName">NSWindow</string>
+ </object>
+ </dictionary>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/LionAutoLayoutTestingAppDelegate.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">NSLayoutConstraint</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">

0 comments on commit 89ec4c8

Please sign in to comment.
Something went wrong with that request. Please try again.