0

I am making my first OSX app. My appDelegate has a window which has a contentView of NSViewController. This NSViewController has a custom view which displays on startup. I added an NSScrollView as a property of my NSViewController, and in the xib I put it in the correct position and referenced it to the files owner (the NSViewController). The scrollView never displays when the view is displayed. The code that includes the scrollView is as follows:

in the .h for the viewController:

#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

in the .m for the 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

If anyone could help that would be awesome! Thanks!

Andrew
  • 63
  • 1
  • 7

1 Answers1

1

If I understand your issue, you don't need to alloc/init the scrollView1 if it is well-connected to the xib file. The xib allocates it for your since the scrollView1 is an object of that xib. If you NSLog(@"%@",[scrollView1 description]) before and after your allocation, It should give you two different objects. I would try :

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

Now you're adding the xib scrollView1 object to the self.view. Hope it helps!