0

初めての OSX アプリを作成しています。私のappDelegateには、NSViewControllerのcontentViewを持つウィンドウがあります。この NSViewController には、起動時に表示されるカスタム ビューがあります。NSScrollView を NSViewController のプロパティとして追加し、xib で正しい位置に配置して、ファイルの所有者 (NSViewController) を参照しました。ビューが表示されている場合、scrollView は表示されません。scrollView を含むコードは次のとおりです。

viewController の .h で:

#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

viewController の .m で:

#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

誰かがそれを助けることができれば、それは素晴らしいことです! ありがとう!

4

1 に答える 1

1

あなたの問題を理解していれば、xib ファイルに適切に接続されていれば、scrollView1 を割り当て/初期化する必要はありません。scrollView1はそのxibのオブジェクトであるため、xibはそれをあなたに割り当てます。NSLog(@"%@",[scrollView1 description])割り当ての前後で、2 つの異なるオブジェクトが得られるはずです。私は試してみます:

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

ここで、xib scrollView1 オブジェクトを self.view に追加しています。それが役に立てば幸い!

于 2013-01-18T21:27:47.227 に答える