20309 发表于 2015-12-30 16:03:15

View Swapping(Chapter 29 of Cocoa Programming for Mac OS X)

1 #import "MyDocument.h"
2 #import "DepartmentViewController.h"
3 #import "EmployeeViewController.h"
4
5 @implementation MyDocument
6
7 - (id)init
8 {
9   ;
10   viewControllers = [ init];
11   
12   ManagingViewController *vc = [ init];
13   ];
14   ;
15   ;
16   
17   vc = [ init];
18   ];
19   ;
20   ;
21   
22   return self;
23 }
24
25 - (void)displayViewController:(ManagingViewController *)vc
26 {
27   NSWindow *w = ;
28   BOOL ended = ;
29   if (!ended)
30   {
31         NSBeep();
32         return;
33   }
34   
35   NSView *v = ;
36   
37   NSSize currentSize = [ frame].size;
38   NSSize newSize = .size;
39   float deltaWidth = newSize.width - currentSize.width;
40   float deltaHeight = newSize.height - currentSize.height;
41   NSRect windowFrame = ;
42   windowFrame.size.height += deltaHeight;
43   windowFrame.origin.y -= deltaHeight;
44   windowFrame.size.width += deltaWidth;
45   
46   ;
47   ;
48   
49   ;
50 }
51
52 - (NSString *)windowNibName
53 {
54   // Override returning the nib file name of the document
55   // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
56   return @"MyDocument";
57 }
58
59 - (void)windowControllerDidLoadNib:(NSWindowController *)aController
60 {
61   ;
62   NSMenu *menu = ;
63   int i, itemCount;
64   itemCount = ;
65   for(i=0; i<itemCount; i++)
66   {
67         NSViewController *vc = ;
68         NSMenuItem *mi = [ initWithTitle: action:@selector(changeViewController:) keyEquivalent:@""];
69         ;
70         ;
71         ;
72   }
73   
74   ];
75   ;
76 }
77
78 - (IBAction)changeViewController:(id)sender
79 {
80   int i = ;
81   ManagingViewController *vc = ;
82   ;
83 }
84
85 - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
86   /*
87      Insert code here to write your document to data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning nil.
88   You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
89   */
90   if (outError) {
91         *outError = ;
92   }
93   return nil;
94 }
95
96 - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
97   /*
98   Insert code here to read your document from the given data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning NO.
99   You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
100   */
101   if (outError) {
102         *outError = ;
103   }
104   return YES;
105 }
106
107 @end
页: [1]
查看完整版本: View Swapping(Chapter 29 of Cocoa Programming for Mac OS X)