2013-01-18 27 views
0

我正在製作我的第一個OSX應用程序。我的appDelegate有一個窗口,它有一個NSViewController的contentView。此NSViewController具有啓動時顯示的自定義視圖。我添加了一個NSScrollView作爲我的NSViewController的一個屬性,並且在xib中我將它放在了正確的位置,並將它引用到文件所有者(NSViewController)。顯示視圖時,scrollView不會顯示。它包括了滾動的代碼如下:在.M爲的viewControllerNSViewController中的NSScrollView

#import <Foundation/Foundation.h> 
#import <Cocoa/Cocoa.h> 
#import "StockData.h" 
@interface MasterViewController : NSViewController { 

IBOutlet NSScrollView * scrollView1; 
} 
@property (retain) IBOutlet NSScrollView * scrollView1; 
@property (retain) NSView * contents; 

@end 

在.H爲的viewController

#import "MasterViewController.h" 
#import <math.h> 
#import <Foundation/Foundation.h> 

@implementation MasterViewController 
@synthesize scrollView1, contents; 

- (void) awakeFromNib 
{ 
self.scrollView1 = [[NSScrollView alloc] init]; 
self.contents = [[NSView alloc] initWithFrame:NSMakeRect(0,0,430,1000)]; 
[self.view addSubview:scrollView1]; 
[self.scrollView1 setDocumentView:self.contents]; 
} 

@end 

如果有人可以幫助那會太棒了!謝謝!

+0

使用'initWithFrame'而不是'init'作爲scrollView,或使用子視圖自動調整。 – 9dan

+0

我試了兩個,它不工作:( – Andrew

回答

1

如果我理解你的問題,如果它連接到xib文件,你不需要分配/ init scrollView1。 xib爲你分配它,因爲scrollView1是該xib的一個對象。如果你在分配前後NSLog(@"%@",[scrollView1 description]),它應該給你兩個不同的對象。我會嘗試:

self.contents = [[NSView alloc] initWithFrame:NSMakeRect(0,0,430,1000)]; 
[self.view addSubview:scrollView1]; 
[self.scrollView1 setDocumentView:self.contents]; 

現在您將xib scrollView1對象添加到self.view。 希望它有幫助!